/*---------------------------------------------------------------------*/ static int pkteng_link(lua_State *L) { TRACE_LUA_FUNC_START(); PktEngine_Intf *pe = check_pkteng(L, 1); Linker_Intf *linker; Brick *first_brick; int nargs = lua_gettop(L); int i; /* check if args2 is user-data */ luaL_checktype(L, 2, LUA_TUSERDATA); /* Retrieve linker data */ linker = (Linker_Intf *)luaL_optudata(L, 2); /* set values as default */ pe->batch = DEFAULT_BATCH_SIZE; pe->qid = -1; /* if 3rd arg is passed, fill it with batch size */ if (nargs >= 3) pe->batch = luaL_checkint(L, 3); /* if 4th arg is passed, fill it with qid */ if (nargs >= 4) pe->qid = luaL_checkint(L, 4); lua_settop(L, 1); TRACE_DEBUG_LOG("Engine info so far...:\n" "\tName: %s\n" "\tCpu: %d\n" "\tBatch: %d\n" "\tQid: %d\n", pe->eng_name, pe->cpu, pe->batch, pe->qid); for (i = 0; i < linker->input_count; i++) { /* link the source(s) with the packet engine */ pktengine_link_iface((uint8_t *)pe->eng_name, (uint8_t *)linker->input_link[i], pe->batch, pe->qid); TRACE_LOG("Linking %s with link %s with batch size: %d and qid: %d\n", pe->eng_name, linker->input_link[i], pe->batch, pe->qid); } first_brick = createBrick(linker->type); if (first_brick == NULL) { TRACE_LUA_FUNC_END(); return 1; } first_brick->eng = engine_find((unsigned char *)pe->eng_name); first_brick->elib->init(first_brick, linker); if (first_brick->eng == NULL) { TRACE_LOG("Could not find engine with name: %s\n", pe->eng_name); TRACE_LUA_FUNC_END(); free(first_brick); return 1; } first_brick->elib->link(first_brick, linker); /* if there are pipelines, link them as well */ while (linker->next_linker != NULL) { linker = linker->next_linker; first_brick->elib->link(first_brick, linker); } TRACE_LUA_FUNC_END(); return 1; }
/** * This brick needs a customized link function since it needs to push * packets from multiple ifaces */ void merge_link(struct Brick *from, PktEngine_Intf *pe, Linker_Intf *linker) { TRACE_BRICK_FUNC_START(); int i, j, k, rc; engine *eng; linkdata *lbd; int div_type = (linker->type == LINKER_DUP) ? COPY : SHARE; lbd = (linkdata *)(&from->lnd); eng = engine_find(from->eng->name); /* sanity engine check */ if (eng == NULL) { TRACE_LOG("Can't find engine with name: %s\n", from->eng->name); TRACE_BRICK_FUNC_END(); return; } /* if engine is already running, then don't connect bricks */ if (eng->run == 1) { TRACE_LOG("Can't open channel" "engine %s is already running\n", eng->name); TRACE_BRICK_FUNC_END(); return; } if (eng->esrc == NULL) { strcpy(lbd->ifname, (char *)linker->input_link[0]); lbd->count = linker->output_count; for (i = 0; i < linker->input_count; i++) { /* link the source(s) with the packet engine */ pktengine_link_iface((uint8_t *)eng->name, (uint8_t *)linker->input_link[i], pe->batch, pe->qid); TRACE_LOG("Linking %s with link %s with batch size: %d and qid: %d\n", eng->name, linker->input_link[i], pe->batch, pe->qid); } for (k = 0; k < (int)eng->no_of_sources; k++) eng->esrc[k]->brick = from; lbd->external_links = calloc(lbd->count, sizeof(void *)); if (lbd->external_links == NULL) { TRACE_LOG("Can't allocate external link contexts " "for load balancer\n"); TRACE_BRICK_FUNC_END(); return; } } for (j = 0; j < linker->input_count; j++) { for (i = 0; i < linker->output_count; i++) { rc = eng->iom.create_external_link((char *)linker->input_link[0], (char *)linker->output_link[i], div_type, eng->esrc[j]); if (rc == -1) { TRACE_LOG("Failed to open channel %s\n", linker->output_link[i]); TRACE_BRICK_FUNC_END(); return; } } } TRACE_BRICK_FUNC_END(); }