From d92759bde48a830bd87498ee95c85cf2b8184c9c Mon Sep 17 00:00:00 2001 From: micpapal Date: Fri, 16 Feb 2018 04:11:07 -0800 Subject: connections on the server side are created automatically Change-Id: Idd97ef1dbc4a84d5eeee17538d54668a8f2361b9 Signed-off-by: micpapal --- .../forwarder/metis/config/metis_Configuration.c | 25 +++++++++++- metis/ccnx/forwarder/metis/io/metis_UdpListener.c | 44 +++++++++++----------- 2 files changed, 44 insertions(+), 25 deletions(-) diff --git a/metis/ccnx/forwarder/metis/config/metis_Configuration.c b/metis/ccnx/forwarder/metis/config/metis_Configuration.c index 3703c6ef..4a72ab41 100644 --- a/metis/ccnx/forwarder/metis/config/metis_Configuration.c +++ b/metis/ccnx/forwarder/metis/config/metis_Configuration.c @@ -47,6 +47,7 @@ #include #include +#include #include #include @@ -351,14 +352,34 @@ static CCNxControl * metisConfiguration_ProcessCreateTunnel(MetisConfiguration *config, CCNxControl *control, unsigned ingressId) { bool success = false; + bool exists = true; CPIInterfaceIPTunnel *iptun = cpiLinks_CreateIPTunnelFromControlMessage(control); const char *symbolicName = cpiInterfaceIPTunnel_GetSymbolicName(iptun); + const CPIAddress *source; + const CPIAddress *destination; + if (!metisSymbolicNameTable_Exists(config->symbolicNameTable, symbolicName)) { - const CPIAddress *source = cpiInterfaceIPTunnel_GetSourceAddress(iptun); - const CPIAddress *destination = cpiInterfaceIPTunnel_GetDestinationAddress(iptun); + source = cpiInterfaceIPTunnel_GetSourceAddress(iptun); + destination = cpiInterfaceIPTunnel_GetDestinationAddress(iptun); + + MetisAddressPair *pair = metisAddressPair_Create(source, destination); + const MetisConnection *conn = + metisConnectionTable_FindByAddressPair(metisForwarder_GetConnectionTable(config->metis), pair); + + metisAddressPair_Release(&pair); + + if(conn == NULL){ + //the connection does not exists (even without a name) + exists = false; + } + } + + if(!exists){ + source = cpiInterfaceIPTunnel_GetSourceAddress(iptun); + destination = cpiInterfaceIPTunnel_GetDestinationAddress(iptun); MetisIoOperations *ops = NULL; switch (cpiInterfaceIPTunnel_GetTunnelType(iptun)) { diff --git a/metis/ccnx/forwarder/metis/io/metis_UdpListener.c b/metis/ccnx/forwarder/metis/io/metis_UdpListener.c index 1bd54187..342f7ce4 100644 --- a/metis/ccnx/forwarder/metis/io/metis_UdpListener.c +++ b/metis/ccnx/forwarder/metis/io/metis_UdpListener.c @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -459,23 +460,20 @@ _lookupConnectionId(MetisUdpListener *udp, MetisAddressPair *pair, unsigned *out * @return The connection id for the new connection */ -//for the moment this is not used anymore -//we need to handle the connection tables in a better way in order to avoid multiple connections -//with the same address pair. -/*static unsigned - * _createNewConnection(MetisUdpListener *udp, int fd, const MetisAddressPair *pair) - * { - * bool isLocal = false; - * - * // metisUdpConnection_Create takes ownership of the pair - * MetisIoOperations *ops = metisUdpConnection_Create(udp->metis, fd, pair, isLocal); - * MetisConnection *conn = metisConnection_Create(ops); - * - * metisConnectionTable_Add(metisForwarder_GetConnectionTable(udp->metis), conn); - * unsigned connid = metisIoOperations_GetConnectionId(ops); - * - * return connid; - * }*/ +static unsigned +_createNewConnection(MetisUdpListener * udp, int fd, const MetisAddressPair * pair) +{ + bool isLocal = false; + + // metisUdpConnection_Create takes ownership of the pair + MetisIoOperations * ops = metisUdpConnection_Create(udp->metis, fd, pair, isLocal); + MetisConnection * conn = metisConnection_Create(ops); + + metisConnectionTable_Add(metisForwarder_GetConnectionTable(udp->metis), conn); + unsigned connid = metisIoOperations_GetConnectionId(ops); + + return connid; +} static void _receivePacket(MetisUdpListener *udp, int fd, size_t packetLength, struct sockaddr_storage *peerIpAddress, socklen_t peerIpAddressLength) @@ -485,12 +483,12 @@ _receivePacket(MetisUdpListener *udp, int fd, size_t packetLength, struct sockad bool foundConnection = _lookupConnectionId(udp, pair, &connid); if (!foundConnection) { - PARCEventBuffer *readbuffer = parcEventBuffer_Create(); - parcEventBuffer_ReadFromFileDescriptor(readbuffer, fd, packetLength); - parcEventBuffer_Destroy(&readbuffer); - metisAddressPair_Release(&pair); - return; - //connid = _createNewConnection(udp, fd, pair); + //PARCEventBuffer *readbuffer = parcEventBuffer_Create(); + //parcEventBuffer_ReadFromFileDescriptor(readbuffer, fd, packetLength); + //parcEventBuffer_Destroy(&readbuffer); + //metisAddressPair_Release(&pair); + //return; + connid = _createNewConnection(udp, fd, pair); } metisAddressPair_Release(&pair); -- cgit 1.2.3-korg