diff options
Diffstat (limited to 'hicn-light/src/hicn/io')
-rw-r--r-- | hicn-light/src/hicn/io/hicnConnection.c | 129 | ||||
-rw-r--r-- | hicn-light/src/hicn/io/hicnListener.c | 31 | ||||
-rw-r--r-- | hicn-light/src/hicn/io/ioOperations.c | 5 | ||||
-rw-r--r-- | hicn-light/src/hicn/io/ioOperations.h | 5 | ||||
-rw-r--r-- | hicn-light/src/hicn/io/streamConnection.c | 7 | ||||
-rw-r--r-- | hicn-light/src/hicn/io/udpConnection.c | 23 | ||||
-rw-r--r-- | hicn-light/src/hicn/io/udpListener.c | 13 |
7 files changed, 42 insertions, 171 deletions
diff --git a/hicn-light/src/hicn/io/hicnConnection.c b/hicn-light/src/hicn/io/hicnConnection.c index e35454438..646cea990 100644 --- a/hicn-light/src/hicn/io/hicnConnection.c +++ b/hicn-light/src/hicn/io/hicnConnection.c @@ -56,18 +56,6 @@ typedef struct hicn_state { struct sockaddr *localAddress; socklen_t localAddressLength; - // this address contains one of the content names reachable - // throught the connection peer. We need this address beacuse it is - // the only way we have to conntact the next hop, since the main tun - // does not have address. Notice that a connection that sends probes - // is a connection that sends interest. In a "data" connection this - // value will remain NULL. We refresh the content address every time - // we send a probe, in this way we don't need to waste to much time in - // copy the address, but we can also react to the routing changes - struct sockaddr *probeDestAddress; - socklen_t probeDestAddressLength; - bool refreshProbeDestAddress; - bool isLocal; bool isUp; unsigned id; @@ -94,8 +82,7 @@ static bool _isUp(const IoOperations *ops); static bool _isLocal(const IoOperations *ops); static void _destroy(IoOperations **opsPtr); static list_connections_type _getConnectionType(const IoOperations *ops); -static Ticks _sendProbe(IoOperations *ops, unsigned probeType, - uint8_t *message); +static void _sendProbe(IoOperations *ops, uint8_t *message); static connection_state_t _getState(const IoOperations *ops); static void _setState(IoOperations *ops, connection_state_t state); static connection_state_t _getAdminState(const IoOperations *ops); @@ -147,8 +134,6 @@ static IoOperations _template = { static void _setConnectionState(_HicnState *Hicn, bool isUp); static bool _saveSockaddr(_HicnState *hicnConnState, const AddressPair *pair); -static void _refreshProbeDestAddress(_HicnState *hicnConnState, - const uint8_t *message); IoOperations *hicnConnection_Create(Forwarder *forwarder, const char * interfaceName, int fd, const AddressPair *pair, bool isLocal) { @@ -225,8 +210,6 @@ static void _destroy(IoOperations **opsPtr) { addressPair_Release(&hicnConnState->addressPair); parcMemory_Deallocate((void **)&(hicnConnState->peerAddress)); parcMemory_Deallocate((void **)&(hicnConnState->localAddress)); - if (hicnConnState->probeDestAddress != NULL) - parcMemory_Deallocate((void **)&(hicnConnState->probeDestAddress)); messenger_Send( forwarder_GetMessenger(hicnConnState->forwarder), @@ -328,12 +311,6 @@ static bool _send(IoOperations *ops, const Address *dummy, Message *message) { &(((struct sockaddr_in *)hicnConnState->localAddress) ->sin_addr.s_addr)); } - - // only in this case we may need to set the probeDestAddress - if (hicnConnState->refreshProbeDestAddress) { - _refreshProbeDestAddress(hicnConnState, message_FixedHeader(message)); - } - } else if (message_GetType(message) == MessagePacketType_WldrNotification) { // here we don't need to do anything for now } else { @@ -395,64 +372,31 @@ static list_connections_type _getConnectionType(const IoOperations *ops) { return CONN_HICN; } -static Ticks _sendProbe(IoOperations *ops, unsigned probeType, - uint8_t *message) { +static void _sendProbe(IoOperations *ops, uint8_t *message) { parcAssertNotNull(ops, "Parameter ops must be non-null"); - _HicnState *hicnConnState = (_HicnState *)ioOperations_GetClosure(ops); - - if ((hicnConnState->peerAddressLength == sizeof(struct sockaddr_in)) || - (hicnConnState->localAddressLength == sizeof(struct sockaddr_in))) - return false; - - if (hicnConnState->probeDestAddress == NULL && - probeType == PACKET_TYPE_PROBE_REPLY) { - uint8_t *pkt = parcMemory_AllocateAndClear( - messageHandler_GetICMPPacketSize(IPv6_TYPE)); - messageHandler_SetProbePacket( - pkt, probeType, - (struct in6_addr *)messageHandler_GetDestination(message), - (struct in6_addr *)messageHandler_GetSource(message)); - - ssize_t writeLength = write(hicnConnState->hicnListenerSocket, pkt, - messageHandler_GetICMPPacketSize(IPv6_TYPE)); - parcMemory_Deallocate((void **)&pkt); + _HicnState *hicnConnState = (_HicnState *)ioOperations_GetClosure(ops); - if (writeLength < 0) { - return 0; + if(messageHandler_IsInterest(message)){// + // this is an interest packet. We need to put the local address in the + // source field + if (messageHandler_GetIPPacketType(message) == IPv6_TYPE) { + messageHandler_SetSource_IPv6(message, + &((struct sockaddr_in6 *)hicnConnState->localAddress)->sin6_addr); + } else { + messageHandler_SetSource_IPv4(message, + &(((struct sockaddr_in *)hicnConnState->localAddress) + ->sin_addr.s_addr)); } + }//if is a data packet the packet is already set (see + //messageHandler_CreateProbeReply) - } else if (hicnConnState->probeDestAddress != NULL && - probeType == PACKET_TYPE_PROBE_REQUEST) { - hicnConnState->refreshProbeDestAddress = true; - - uint8_t *pkt = parcMemory_AllocateAndClear( - messageHandler_GetICMPPacketSize(IPv6_TYPE)); - messageHandler_SetProbePacket( - pkt, probeType, - &((struct sockaddr_in6 *)hicnConnState->localAddress)->sin6_addr, - &((struct sockaddr_in6 *)hicnConnState->probeDestAddress)->sin6_addr); - - ssize_t writeLength = write(hicnConnState->hicnListenerSocket, pkt, - messageHandler_GetICMPPacketSize(IPv6_TYPE)); - - parcMemory_Deallocate((void **)&pkt); + ssize_t writeLength = write(hicnConnState->hicnListenerSocket, message, + messageHandler_GetTotalPacketLength(message)); - if (writeLength < 0) { - return 0; - } - - } else { - if (hicnConnState->probeDestAddress == NULL && - probeType == PACKET_TYPE_PROBE_REQUEST) { - // this happen for the first probe - hicnConnState->refreshProbeDestAddress = true; - } - // do nothing - return 0; + if (writeLength < 0) { + return; } - - return forwarder_GetTicks(hicnConnState->forwarder); } // ================================================================= @@ -481,11 +425,6 @@ static bool _saveSockaddr(_HicnState *hicnConnState, const AddressPair *pair) { addressGetInet(localAddress, (struct sockaddr_in *)hicnConnState->localAddress); hicnConnState->localAddressLength = (socklen_t)bytes; - - hicnConnState->probeDestAddress = NULL; - hicnConnState->probeDestAddressLength = (socklen_t)bytes; - hicnConnState->refreshProbeDestAddress = false; - success = true; break; } @@ -507,11 +446,6 @@ static bool _saveSockaddr(_HicnState *hicnConnState, const AddressPair *pair) { addressGetInet6(localAddress, (struct sockaddr_in6 *)hicnConnState->localAddress); hicnConnState->localAddressLength = (socklen_t)bytes; - - hicnConnState->probeDestAddress = NULL; - hicnConnState->probeDestAddressLength = (socklen_t)bytes; - hicnConnState->refreshProbeDestAddress = false; - success = true; break; } @@ -529,31 +463,6 @@ static bool _saveSockaddr(_HicnState *hicnConnState, const AddressPair *pair) { return success; } -static void _refreshProbeDestAddress(_HicnState *hicnConnState, - const uint8_t *message) { - if ((hicnConnState->peerAddressLength == sizeof(struct sockaddr_in)) || - (hicnConnState->localAddressLength == sizeof(struct sockaddr_in))) - return; - - if (hicnConnState->probeDestAddress == NULL) { - hicnConnState->probeDestAddress = - parcMemory_AllocateAndClear(sizeof(struct sockaddr_in6)); - parcAssertNotNull(hicnConnState->probeDestAddress, - "parcMemory_Allocate(%zu) returned NULL", - sizeof(struct sockaddr_in6)); - } - - ((struct sockaddr_in6 *)hicnConnState->probeDestAddress)->sin6_family = - AF_INET6; - ((struct sockaddr_in6 *)hicnConnState->probeDestAddress)->sin6_port = - htons(1234); - ((struct sockaddr_in6 *)hicnConnState->probeDestAddress)->sin6_scope_id = 0; - ((struct sockaddr_in6 *)hicnConnState->probeDestAddress)->sin6_flowinfo = 0; - ((struct sockaddr_in6 *)hicnConnState->probeDestAddress)->sin6_addr = - *((struct in6_addr *)messageHandler_GetDestination(message)); - hicnConnState->refreshProbeDestAddress = false; -} - static void _setConnectionState(_HicnState *hicnConnState, bool isUp) { parcAssertNotNull(hicnConnState, "Parameter HICN must be non-null"); diff --git a/hicn-light/src/hicn/io/hicnListener.c b/hicn-light/src/hicn/io/hicnListener.c index 5a47982ff..bc49f4cee 100644 --- a/hicn-light/src/hicn/io/hicnListener.c +++ b/hicn-light/src/hicn/io/hicnListener.c @@ -85,7 +85,6 @@ static const Connection * _lookupConnection(ListenerOps * listener, const Addres static Message *_readMessage(ListenerOps * listener, int fd, uint8_t *msgBuffer); static void _hicnListener_readcb(int fd, PARCEventType what, void *listener_void); static Address *_createAddressFromPacket(uint8_t *msgBuffer); -static void _handleProbeMessage(ListenerOps * listener, uint8_t *msgBuffer); static void _handleWldrNotification(ListenerOps *listener, uint8_t *msgBuffer); static void _readFrameToDiscard(HicnListener *hicn, int fd); @@ -182,8 +181,6 @@ static Message *_readMessage(ListenerOps * listener, int fd, uint8_t *msgBuffer) } } else if (messageHandler_IsWldrNotification(msgBuffer)) { _handleWldrNotification(listener, msgBuffer); - } else if (messageHandler_IsLoadBalancerProbe(msgBuffer)) { - _handleProbeMessage(listener, msgBuffer); } else { messageHandler_handleHooks(hicn->forwarder, msgBuffer, listener, fd, NULL); parcMemory_Deallocate((void **)&msgBuffer); @@ -639,29 +636,6 @@ static Address *_createAddressFromPacket(uint8_t *msgBuffer) { return packetAddr; } -static void _handleProbeMessage(ListenerOps * listener, uint8_t *msgBuffer) { - HicnListener * hicn = (HicnListener *)listener->context; - - Address *packetAddr = _createAddressFromPacket(msgBuffer); - AddressPair * pair = addressPair_Create(packetAddr, /* dummy */ hicn->localAddress); - - if (!packetAddr) - goto DROP; - - // we drop all the probes for a connection that does not exists - const Connection *conn = _lookupConnection(listener, pair); - if (!conn) - goto DROP; - - connection_HandleProbe((Connection *)conn, msgBuffer, - forwarder_GetTicks(hicn->forwarder)); - -DROP: - addressPair_Release(&pair); - addressDestroy(&packetAddr); - parcMemory_Deallocate((void **)&msgBuffer); -} - static void _handleWldrNotification(ListenerOps *listener, uint8_t *msgBuffer) { HicnListener * hicn = (HicnListener *)listener->context; @@ -693,8 +667,3 @@ static void _handleWldrNotification(ListenerOps *listener, uint8_t *msgBuffer) { message_Release(&message); } - - - - - diff --git a/hicn-light/src/hicn/io/ioOperations.c b/hicn-light/src/hicn/io/ioOperations.c index 336e9f12e..0087b320a 100644 --- a/hicn-light/src/hicn/io/ioOperations.c +++ b/hicn-light/src/hicn/io/ioOperations.c @@ -64,9 +64,8 @@ list_connections_type ioOperations_GetConnectionType(const IoOperations *ops) { return ops->getConnectionType(ops); } -Ticks ioOperations_SendProbe(IoOperations *ops, unsigned probeType, - uint8_t *message) { - return ops->sendProbe(ops, probeType, message); +void ioOperations_SendProbe(IoOperations *ops, uint8_t *message) { + ops->sendProbe(ops, message); } diff --git a/hicn-light/src/hicn/io/ioOperations.h b/hicn-light/src/hicn/io/ioOperations.h index ee8720e77..5d9befac3 100644 --- a/hicn-light/src/hicn/io/ioOperations.h +++ b/hicn-light/src/hicn/io/ioOperations.h @@ -84,7 +84,7 @@ struct io_ops { void (*destroy)(IoOperations **opsPtr); const void *(*class)(const IoOperations *ops); list_connections_type (*getConnectionType)(const IoOperations *ops); - Ticks (*sendProbe)(IoOperations *ops, unsigned probeType, uint8_t *message); + void (*sendProbe)(IoOperations *ops, uint8_t *message); connection_state_t (*getState)(const IoOperations *ops); void (*setState)(IoOperations *ops, connection_state_t state); connection_state_t (*getAdminState)(const IoOperations *ops); @@ -382,8 +382,7 @@ const void *ioOperations_Class(const IoOperations *ops); */ list_connections_type ioOperations_GetConnectionType(const IoOperations *ops); -Ticks ioOperations_SendProbe(IoOperations *ops, unsigned probeType, - uint8_t *message); +void ioOperations_SendProbe(IoOperations *ops, uint8_t *message); /** diff --git a/hicn-light/src/hicn/io/streamConnection.c b/hicn-light/src/hicn/io/streamConnection.c index 27ec45d48..00298d1b0 100644 --- a/hicn-light/src/hicn/io/streamConnection.c +++ b/hicn-light/src/hicn/io/streamConnection.c @@ -88,8 +88,7 @@ static void _streamConnection_DestroyOperations(IoOperations **opsPtr); static void _setConnectionState(_StreamState *stream, bool isUp); static list_connections_type _streamConnection_GetConnectionType( const IoOperations *ops); -static Ticks _sendProbe(IoOperations *ops, unsigned probeType, - uint8_t *message); +static void _sendProbe(IoOperations *ops, uint8_t *message); static connection_state_t _streamConnection_getState(const IoOperations *ops); static void _streamConnection_setState(IoOperations *ops, connection_state_t state); static connection_state_t _streamConnection_getAdminState(const IoOperations *ops); @@ -437,10 +436,8 @@ list_connections_type _streamConnection_GetConnectionType( return CONN_TCP; } -static Ticks _sendProbe(IoOperations *ops, unsigned probeType, - uint8_t *message) { +static void _sendProbe(IoOperations *ops, uint8_t *message) { // we don't need to implemet this here, it is a local connection - return 0; } // ================================================================= diff --git a/hicn-light/src/hicn/io/udpConnection.c b/hicn-light/src/hicn/io/udpConnection.c index 4e29eba7d..b22b1227f 100644 --- a/hicn-light/src/hicn/io/udpConnection.c +++ b/hicn-light/src/hicn/io/udpConnection.c @@ -79,8 +79,7 @@ static bool _isUp(const IoOperations *ops); static bool _isLocal(const IoOperations *ops); static void _destroy(IoOperations **opsPtr); static list_connections_type _getConnectionType(const IoOperations *ops); -static Ticks _sendProbe(IoOperations *ops, unsigned probeType, - uint8_t *message); +static void _sendProbe(IoOperations *ops, uint8_t *message); static connection_state_t _getState(const IoOperations *ops); static void _setState(IoOperations *ops, connection_state_t state); static connection_state_t _getAdminState(const IoOperations *ops); @@ -350,10 +349,22 @@ static list_connections_type _getConnectionType(const IoOperations *ops) { return CONN_UDP; } -static Ticks _sendProbe(IoOperations *ops, unsigned probeType, - uint8_t *message) { - //TODO - return 0; +static void _sendProbe(IoOperations *ops, uint8_t *message) { + parcAssertNotNull(ops, "Parameter ops must be non-null"); + parcAssertNotNull(message, "Parameter message must be non-null"); + _UdpState *udpConnState = (_UdpState *)ioOperations_GetClosure(ops); + + if(udpConnState->isLocal) + return; + + ssize_t writeLength = + sendto(udpConnState->udpListenerSocket, message, + messageHandler_GetTotalPacketLength(message), 0, udpConnState->peerAddress, + udpConnState->peerAddressLength); + + if (writeLength < 0) { + return; + } } // ================================================================= diff --git a/hicn-light/src/hicn/io/udpListener.c b/hicn-light/src/hicn/io/udpListener.c index ebb24022e..21b4f6190 100644 --- a/hicn-light/src/hicn/io/udpListener.c +++ b/hicn-light/src/hicn/io/udpListener.c @@ -476,11 +476,6 @@ static unsigned _createNewConnection(ListenerOps * listener, int fd, return connid; } -static void _handleProbeMessage(UdpListener *udp, uint8_t *msgBuffer) { - // TODO - parcMemory_Deallocate((void **)&msgBuffer); -} - static void _handleWldrNotification(UdpListener *udp, unsigned connId, uint8_t *msgBuffer) { const Connection *conn = connectionTable_FindById( @@ -547,16 +542,8 @@ static Message *_readMessage(ListenerOps * listener, int fd, } else if (messageHandler_IsWldrNotification(packet)) { *processed = true; _handleWldrNotification(udp, connid, packet); - } else if (messageHandler_IsLoadBalancerProbe(packet)) { - *processed = true; - _handleProbeMessage(udp, packet); } else { -#if 0 - if (!foundConnection) - connid = _createNewConnection(listener, fd, pair); -#endif - *processed = messageHandler_handleHooks(udp->forwarder, packet, listener, fd, pair); } |