예제 #1
0
/**
 * Add an IP-based tunnel.
 *
 * The call cal fail if the symbolic name is a duplicate.  It could also fail if there's an problem creating
 * the local side of the tunnel (i.e. the local socket address is not usable).
 *
 * @return true Tunnel added
 * @return false Tunnel not added (an error)
 */
static CCNxControl *
metisConfiguration_ProcessCreateTunnel(MetisConfiguration *config, CCNxControl *control, unsigned ingressId)
{
    bool success = false;

    CPIInterfaceIPTunnel *iptun = cpiLinks_CreateIPTunnelFromControlMessage(control);

    const char *symbolicName = cpiInterfaceIPTunnel_GetSymbolicName(iptun);

    if (!metisSymbolicNameTable_Exists(config->symbolicNameTable, symbolicName)) {
        const CPIAddress *source = cpiInterfaceIPTunnel_GetSourceAddress(iptun);
        const CPIAddress *destination = cpiInterfaceIPTunnel_GetDestinationAddress(iptun);

        MetisIoOperations *ops = NULL;
        switch (cpiInterfaceIPTunnel_GetTunnelType(iptun)) {
            case IPTUN_TCP:
                ops = metisTcpTunnel_Create(config->metis, source, destination);
                break;
            case IPTUN_UDP:
                ops = metisUdpTunnel_Create(config->metis, source, destination);
                break;
            case IPTUN_GRE:
                metisLogger_Log(config->logger, MetisLoggerFacility_Config, PARCLogLevel_Error, __func__,
                                "Unsupported tunnel protocol: GRE");
                break;
            default:
                metisLogger_Log(config->logger, MetisLoggerFacility_Config, PARCLogLevel_Error, __func__,
                                "Unsupported tunnel protocol: %d",
                                cpiInterfaceIPTunnel_GetTunnelType(iptun));
                break;
        }


        if (ops != NULL) {
            MetisConnection *conn = metisConnection_Create(ops);
            metisConnectionTable_Add(metisForwarder_GetConnectionTable(config->metis), conn);
            metisSymbolicNameTable_Add(config->symbolicNameTable, symbolicName, metisConnection_GetConnectionId(conn));

            success = true;

            _logProcessCreateTunnelMessage(config, iptun, PARCLogLevel_Info, "success");
        } else {
            _logProcessCreateTunnelMessage(config, iptun, PARCLogLevel_Warning, "failed, could not create IoOperations");
        }
    } else {
        _logProcessCreateTunnelMessage(config, iptun, PARCLogLevel_Warning, "failed, symbolic name exists");
    }

    // send the ACK or NACK
    CCNxControl *response;
    if (success) {
        response = _createAck(config, control, ingressId);
    } else {
        response = _createNack(config, control, ingressId);
    }

    cpiInterfaceIPTunnel_Release(&iptun);

    return response;
}
예제 #2
0
static bool
_metisConfiguration_AddConnectionEthernet(MetisConfiguration *config, CPIConnectionEthernet *etherConn, CPIAddress *linkAddress, MetisListenerOps *listenerOps)
{
    bool success = false;

    const char *symbolic = cpiConnectionEthernet_GetSymbolicName(etherConn);
    if (!metisSymbolicNameTable_Exists(config->symbolicNameTable, symbolic)) {
        const CPIAddress *remote = cpiConnectionEthernet_GetPeerLinkAddress(etherConn);
        MetisAddressPair *pair = metisAddressPair_Create(linkAddress, remote);

        MetisGenericEther *ether = metisEtherListener_GetGenericEtherFromListener(listenerOps);

        if (ether) {
            MetisIoOperations *ops = metisEtherConnection_Create(config->metis, ether, pair);

            if (ops) {
                MetisConnection *conn = metisConnection_Create(ops);
                assertNotNull(conn, "Failed to create connection");

                metisConnectionTable_Add(metisForwarder_GetConnectionTable(config->metis), conn);
                metisSymbolicNameTable_Add(config->symbolicNameTable, symbolic, metisConnection_GetConnectionId(conn));

                success = true;

                if (metisLogger_IsLoggable(config->logger, MetisLoggerFacility_Config, PARCLogLevel_Debug)) {
                    char *peerAddressString = cpiAddress_ToString(remote);
                    metisLogger_Log(config->logger, MetisLoggerFacility_Config, PARCLogLevel_Debug, __func__,
                                    "Add connection %s on %s to %s, connid %u",
                                    symbolic,
                                    cpiConnectionEthernet_GetInterfaceName(etherConn),
                                    peerAddressString,
                                    metisConnection_GetConnectionId(conn));
                    parcMemory_Deallocate((void **) &peerAddressString);
                }
            }
        } else {
            metisLogger_Log(config->logger, MetisLoggerFacility_Config, PARCLogLevel_Error, __func__,
                            "Could not get MetisGenericEther for listener %p",
                            listenerOps);
        }

        metisAddressPair_Release(&pair);
    } else {
        if (metisLogger_IsLoggable(config->logger, MetisLoggerFacility_Config, PARCLogLevel_Warning)) {
            const CPIAddress *remote = cpiConnectionEthernet_GetPeerLinkAddress(etherConn);
            char *peerAddressString = cpiAddress_ToString(remote);
            metisLogger_Log(config->logger, MetisLoggerFacility_Config, PARCLogLevel_Warning, __func__,
                            "Add connection %s on %s to %s failed, symbolic name exists",
                            symbolic,
                            cpiConnectionEthernet_GetInterfaceName(etherConn),
                            peerAddressString);
            parcMemory_Deallocate((void **) &peerAddressString);
        }
    }

    return success;
}
예제 #3
0
    memset(&metisA_AnyIpAddress, 0, sizeof(metisA_AnyIpAddress));
    metisA_AnyIpAddress.sin_family = PF_INET;
    metisA_AnyIpAddress.sin_addr.s_addr = INADDR_ANY;

    // connect to 127.0.0.1:10002
    struct sockaddr_in metisB_LoopbackAddress;
    memset(&metisB_LoopbackAddress, 0, sizeof(metisB_LoopbackAddress));
    metisB_LoopbackAddress.sin_family = PF_INET;
    metisB_LoopbackAddress.sin_port = htons(metisB_port);
    inet_pton(AF_INET, "127.0.0.1", &(metisB_LoopbackAddress.sin_addr));

    CPIAddress *metisA_localCpiAddress = cpiAddress_CreateFromInet(&metisA_AnyIpAddress);
    CPIAddress *metisA_remoteCpiAddress = cpiAddress_CreateFromInet(&metisB_LoopbackAddress);

    MetisIoOperations *ops = metisTcpTunnel_Create(metis_a, metisA_localCpiAddress, metisA_remoteCpiAddress);
    MetisConnection *conn = metisConnection_Create(ops);
    metisConnectionTable_Add(metisForwarder_GetConnectionTable(metis_a), conn);

    cpiAddress_Destroy(&metisA_localCpiAddress);
    cpiAddress_Destroy(&metisA_remoteCpiAddress);

    // ---- run
    metisDispatcher_RunDuration(dispatcher_a, &((struct timeval) { 0, 1000 }));
    metisDispatcher_RunDuration(dispatcher_b, &((struct timeval) { 0, 1000 }));
    // ----

    // ===============================================
    /* 4) setup route to /foo from a to b */

    CCNxName *ccnxName = ccnxName_CreateFromURI("lci:/2=hello");
    CPIRouteEntry *route = cpiRouteEntry_Create(ccnxName, ops->getConnectionId(ops), NULL, cpiNameRouteProtocolType_STATIC, cpiNameRouteType_LONGEST_MATCH, NULL, 1);