/** * fab_host_create - * * Allocate and initialize a host struct */ static fab_host_t * fab_host_create(uint64_t dpid, uint32_t sw_alias, struct flow *fl) { fab_host_t *host; host = fab_zalloc(sizeof(fab_host_t)); c_rw_lock_init(&host->lock); host->sw.swid = dpid; host->sw.alias = sw_alias; host->sw.port = ntohs(fl->in_port); FAB_MK_TEN_NET_ID(host->hkey.tn_id, fab_extract_tenant_id(fl), fab_extract_network_id(fl)); host->hkey.host_ip = ntohl(fl->nw_src); memcpy(host->hkey.host_mac, fl->dl_src, 6); host->dfl_gw = fl->FL_DFL_GW; return host; }
/** * fab_dump_add_host_cmd_from_flow - * */ static char * fab_dump_add_host_cmd_from_flow(uint64_t dpid, struct flow *fl) { char *pbuf = calloc(1, HOST_PBUF_SZ); int len = 0; struct in_addr in_addr = { .s_addr = fl->nw_src }; len += snprintf(pbuf+len, HOST_PBUF_SZ-len-1, "add fabric-host tenant %hu network %hu host-ip %s host-mac " "%02x:%02x:%02x:%02x:%02x:%02x switch " "0x%llx port %hu %s \r\n", fab_extract_tenant_id(fl), fab_extract_network_id(fl), inet_ntoa(in_addr), fl->dl_src[0], fl->dl_src[1], fl->dl_src[2], fl->dl_src[3], fl->dl_src[4], fl->dl_src[5], dpid, ntohs(fl->in_port), fl->FL_DFL_GW ? "gw" : "non-gw"); assert(len < HOST_PBUF_SZ-1); return pbuf; } static bool check_reply_type(struct cbuf *b, uint32_t cmd_code) { c_ofp_auxapp_cmd_t *cofp_auc = (void *)(b->data); if (ntohs(cofp_auc->header.length) < sizeof(*cofp_auc)) { return false; } if (cofp_auc->header.type != C_OFPT_AUX_CMD || cofp_auc->cmd_code != htonl(cmd_code)) { return false; } return true; }