void ldp_label_rel_with_prepare_msg(ldp_mesg * msg, uint32_t msgid,
  ldp_attr * a, ldp_notif_status status, uint16_t type)
{
  mplsLdpLbl_W_R_Msg_t *rw = NULL;

  ldp_mesg_prepare(msg, type, msgid);
  rw = &msg->u.release;
  if (a->fecTlvExists) {
    rw->fecTlvExists = 1;
    rw->baseMsg.msgLength += setupFecTlv(&rw->fecTlv);
    rw->baseMsg.msgLength += addFecElem2FecTlv(&rw->fecTlv,
      &a->fecTlv.fecElArray[0]);
  }
  if (a->genLblTlvExists) {
    rw->genLblTlvExists = 1;
    rw->baseMsg.msgLength += setupGenLblTlv(&rw->genLblTlv, a->genLblTlv.label);
  }
  if (a->atmLblTlvExists) {
    rw->atmLblTlvExists = 1;
    rw->baseMsg.msgLength += setupAtmLblTlv(&rw->atmLblTlv, 0, 0,
      a->atmLblTlv.flags.flags.vpi, a->atmLblTlv.vci);
  }
  if (a->frLblTlvExists) {
    rw->frLblTlvExists = 1;
    rw->baseMsg.msgLength += setupFrLblTlv(&rw->frLblTlv, 0,
      a->frLblTlv.flags.flags.len, a->frLblTlv.flags.flags.dlci);
  }
  if (a->lspidTlvExists) {
    rw->lspidTlvExists = 1;
    rw->baseMsg.msgLength += setupLspidTlv(&rw->lspidTlv, 0,
      a->lspidTlv.localCrlspId, a->lspidTlv.routerId);
  }
}
void ldp_label_mapping_prepare_msg(ldp_mesg * msg, uint32_t msgid,
  ldp_attr * s_attr)
{
  mplsLdpLblMapMsg_t *map = NULL;
  int i;

  MPLS_ASSERT(msg);

  ldp_mesg_prepare(msg, MPLS_LBLMAP_MSGTYPE, msgid);
  map = &msg->u.map;

  if (s_attr->fecTlvExists) {
    /* JLEU: only 1 FEC is allowed!! */
    map->fecTlvExists = 1;
    map->baseMsg.msgLength += setupFecTlv(&map->fecTlv);
    map->baseMsg.msgLength += addFecElem2FecTlv(&map->fecTlv,
      &s_attr->fecTlv.fecElArray[0]);
  }
  if (s_attr->genLblTlvExists) {
    map->genLblTlvExists = 1;
    map->baseMsg.msgLength += setupGenLblTlv(&map->genLblTlv,
      s_attr->genLblTlv.label);
  }
  if (s_attr->atmLblTlvExists) {
    map->atmLblTlvExists = 1;
    map->baseMsg.msgLength += setupAtmLblTlv(&map->atmLblTlv, 0, 0,
      s_attr->atmLblTlv.flags.flags.vpi, s_attr->atmLblTlv.vci);
  }
  if (s_attr->frLblTlvExists) {
    map->frLblTlvExists = 1;
    map->baseMsg.msgLength += setupFrLblTlv(&map->frLblTlv, 0,
      s_attr->frLblTlv.flags.flags.len, s_attr->frLblTlv.flags.flags.dlci);
  }
  if (s_attr->hopCountTlvExists) {
    map->hopCountTlvExists = 1;
    map->baseMsg.msgLength += setupHopCountTlv(&map->hopCountTlv,
      s_attr->hopCountTlv.hcValue);
  }
  if (s_attr->pathVecTlvExists) {
    map->pathVecTlvExists = 1;
    map->baseMsg.msgLength += setupPathTlv(&map->pathVecTlv);
    for (i = 0; i < MPLS_MAXHOPSNUMBER; i++) {
      if (s_attr->pathVecTlv.lsrId[i]) {
        map->baseMsg.msgLength += addLsrId2PathTlv(&map->pathVecTlv,
          s_attr->pathVecTlv.lsrId[i]);
      }
    }
  }
#if 0
  if (s_attr->lblMsgIdTlvExists) {
  }
  if (s_attr->lspidTlvExists) {
  }
  if (s_attr->trafficTlvExists) {
  }
#endif
}