17static void openFlow_createSocketInterface(NETSIM_ID d);
20static int fn_NetSim_OPEN_FLOW_HandleTimerEvent();
21static int fn_NetSim_OPEN_FLOW_HandleAppInEvent();
26_declspec (dllexport)
int fn_NetSim_OPEN_FLOW_Init(
struct stru_NetSim_Network *NETWORK_Formal,
27 NetSim_EVENTDETAILS *pstruEventDetails_Formal,
28 char *pszAppPath_Formal,
29 char *pszWritePath_Formal,
37 pstruEventDetails_Formal;
40 for (i = 0; i < NETWORK->nDeviceCount; i++)
42 if (isOPENFLOWConfigured(i + 1))
44 ptrOPENFLOW of = GET_OPENFLOW_VAR(i + 1);
45 if (!isSDNController(i + 1))
47 of->sdnControllerId = fn_NetSim_Stack_GetDeviceId_asName(of->sdnControllerDev);
48 if (!of->sdnControllerId)
50 fnNetSimError(
"%s device is not configured as SDN controller.\n"
51 "Disabling OPEN_FLOW protocol in device %d.\n",
53 DEVICE_CONFIGID(i + 1));
54 of->isSDNConfigured =
false;
60 for (i = 0; i < NETWORK->nDeviceCount; i++)
62 if (isOPENFLOWConfigured(i + 1))
64 ptrOPENFLOW of = GET_OPENFLOW_VAR(i + 1);
65 of->myIP = openFlow_find_client_IP(i + 1);
66 if (isSDNController(i + 1))
71 of->INFO.controllerInfo = calloc(1,
sizeof* of->INFO.controllerInfo);
72 openFlow_createSocketInterface(i + 1);
83_declspec (dllexport)
int fn_NetSim_OPEN_FLOW_Run()
85 switch (pstruEventDetails->nEventType)
88 return fn_NetSim_OPEN_FLOW_HandleTimerEvent();
90 case APPLICATION_IN_EVENT:
91 return fn_NetSim_OPEN_FLOW_HandleAppInEvent();
93 fnNetSimError(
"%d event is not for Open flow protocol\n", pstruEventDetails->nEventType);
103_declspec(dllexport)
int fn_NetSim_OPEN_FLOW_Finish()
113_declspec (dllexport)
char* fn_NetSim_OPEN_FLOW_Trace(NETSIM_ID nSubEvent)
124_declspec(dllexport)
int fn_NetSim_OPEN_FLOW_Configure(
void** var)
129 NETSIM_ID nInterfaceId;
130 LAYER_TYPE nLayerType;
133 xmlNetSimNode = var[2];
134 if (!strcmp(tag,
"PROTOCOL_PROPERTY"))
137 nDeviceId = *((NETSIM_ID*)var[3]);
138 nInterfaceId = *((NETSIM_ID*)var[4]);
139 nLayerType = *((LAYER_TYPE*)var[5]);
142 of = GET_OPENFLOW_VAR(nDeviceId);
145 of = calloc(1,
sizeof* of);
146 SET_OPENFLOW_VAR(nDeviceId, of);
148 getXmlVar(&of->isSDNConfigured, OPEN_FLOW_ENABLE, xmlNetSimNode, 1, _BOOL, OPENFLOW);
149 if (of->isSDNConfigured)
151 getXmlVar(&of->isSDNController, SDN_CONTROLLER, xmlNetSimNode, 1, _BOOL, OPENFLOW);
152 if(!of->isSDNController)
153 getXmlVar(&of->sdnControllerDev, SDN_CONTROLLER_DEVICE, xmlNetSimNode, 1, _STRING, OPENFLOW);
163_declspec(dllexport)
int fn_NetSim_OPEN_FLOW_FreePacket(NetSim_PACKET* pstruPacket)
174_declspec(dllexport)
int fn_NetSim_OPEN_FLOW_CopyPacket(NetSim_PACKET* pstruDestPacket, NetSim_PACKET* pstruSrcPacket)
185_declspec(dllexport)
int fn_NetSim_OPEN_FLOW_Metrics(PMETRICSWRITER metricsWriter)
194_declspec(dllexport)
char* fn_NetSim_OPEN_FLOW_ConfigPacketTrace()
202_declspec(dllexport)
char* fn_NetSim_OPEN_FLOW_WritePacketTrace(NetSim_PACKET* pstruPacket,
char** ppszTrace)
209bool isOPENFLOWConfigured(NETSIM_ID d)
211 ptrOPENFLOW of = GET_OPENFLOW_VAR(d);
214 return of->isSDNConfigured;
219static int fn_NetSim_OPEN_FLOW_HandleTimerEvent()
221 switch (pstruEventDetails->nSubEventType)
227 fnNetSimError(
"%d subevent is not for Open flow protocol\n", pstruEventDetails->nSubEventType);
233static void openFlow_createSocketInterface(NETSIM_ID d)
235 ptrOPENFLOW of = GET_OPENFLOW_VAR(d);
237 UINT16 port = (UINT16)(NETSIM_RAND_01() * 65535);
238 of->INFO.controllerInfo->port = port;
239 of->INFO.controllerInfo->controllerId = of->sdnControllerId;
240 of->INFO.controllerInfo->controllerIP = openFlow_find_client_IP(of->sdnControllerId);
241 of->INFO.controllerInfo->sock = fn_NetSim_Socket_CreateNewSocket(d,
242 APP_PROTOCOL_OPENFLOW,
247 openFlow_add_new_client(of->sdnControllerId,
252NETSIM_IPAddress openFlow_find_client_IP(NETSIM_ID d)
255 for (i = 0; i < DEVICE(d)->nNumOfInterface; i++)
257 if (DEVICE_INTERFACE(d, i + 1)->nInterfaceType == INTERFACE_WAN_ROUTER)
258 return DEVICE_NWADDRESS(d, i + 1);
260 return DEVICE_NWADDRESS(d, 1);
263static int fn_NetSim_OPEN_FLOW_HandleAppInEvent()
265 NetSim_PACKET* packet = pstruEventDetails->pPacket;
266 if (!(packet->pstruAppData->nPacketFragment == Segment_Unfragment ||
267 packet->pstruAppData->nPacketFragment == Segment_FirstSegment))
269 fn_NetSim_Packet_FreePacket(packet);
273 switch (packet->nControlDataType)
275 case OFMSGTYPE_COMMAND:
277 ptrOPENFLOWMSG msg = packet->pstruAppData->Packet_AppProtocol;
280 char* ret = openFlow_execute_command(msg->payload,
281 pstruEventDetails->nDeviceId,
286 openFlow_send_response(pstruEventDetails->nDeviceId,
291 fn_NetSim_Packet_FreePacket(packet);
294 case OFMSGTYPE_RESPONSE:
296 ptrOPENFLOWMSG msg = packet->pstruAppData->Packet_AppProtocol;
297 openFlow_print_response(pstruEventDetails->nDeviceId,
302 fn_NetSim_Packet_FreePacket(packet);
306 fnNetSimError(
"Unknown packet type %d arrives in APP_IN event of OPEN_FLOW protocol.",
307 packet->nControlDataType);