Search in sources :

Example 1 with ExtensionMappingAddress

use of org.onosproject.mapping.addresses.ExtensionMappingAddress in project onos by opennetworkinglab.

the class LispExtensionMappingAddressInterpreterTest method getExtMappingAddress.

private ExtensionMappingAddress getExtMappingAddress(ExtensionMappingAddressType type) {
    ExtensionMappingAddress address = null;
    MappingAddress ipv4Addr = MappingAddresses.ipv4MappingAddress(IPV4_PREFIX);
    MappingAddress ipv6Addr = MappingAddresses.ipv6MappingAddress(IPV6_PREFIX);
    if (type.equals(LIST_ADDRESS.type())) {
        address = new LispListAddress.Builder().withIpv4(ipv4Addr).withIpv6(ipv6Addr).build();
    }
    if (type.equals(SEGMENT_ADDRESS.type())) {
        address = new LispSegmentAddress.Builder().withInstanceId(UNIQUE_INT).withAddress(ipv4Addr).build();
    }
    if (type.equals(AS_ADDRESS.type())) {
        address = new LispAsAddress.Builder().withAsNumber(UNIQUE_INT).withAddress(ipv4Addr).build();
    }
    if (type.equals(APPLICATION_DATA_ADDRESS.type())) {
        address = new LispAppDataAddress.Builder().withProtocol(UNIQUE_BYTE).withIpTos(UNIQUE_INT).withLocalPortLow(UNIQUE_SHORT).withLocalPortHigh(UNIQUE_SHORT).withRemotePortLow(UNIQUE_SHORT).withRemotePortHigh(UNIQUE_SHORT).withAddress(ipv4Addr).build();
    }
    if (type.equals(GEO_COORDINATE_ADDRESS.type())) {
        address = new LispGcAddress.Builder().withIsNorth(UNIQUE_BOOLEAN).withLatitudeDegree(UNIQUE_SHORT).withLatitudeMinute(UNIQUE_BYTE).withLatitudeSecond(UNIQUE_BYTE).withIsEast(UNIQUE_BOOLEAN).withLongitudeDegree(UNIQUE_SHORT).withLongitudeMinute(UNIQUE_BYTE).withLongitudeSecond(UNIQUE_BYTE).withAltitude(UNIQUE_INT).withAddress(ipv4Addr).build();
    }
    if (type.equals(NAT_ADDRESS.type())) {
        address = new LispNatAddress.Builder().withMsUdpPortNumber(UNIQUE_SHORT).withEtrUdpPortNumber(UNIQUE_SHORT).withGlobalEtrRlocAddress(ipv4Addr).withMsRlocAddress(ipv4Addr).withPrivateEtrRlocAddress(ipv4Addr).withRtrRlocAddresses(ImmutableList.of(ipv4Addr, ipv6Addr)).build();
    }
    if (type.equals(NONCE_ADDRESS.type())) {
        address = new LispNonceAddress.Builder().withNonce(UNIQUE_INT).withAddress(ipv4Addr).build();
    }
    if (type.equals(MULTICAST_ADDRESS.type())) {
        address = new LispMulticastAddress.Builder().withInstanceId(UNIQUE_INT).withSrcMaskLength(UNIQUE_BYTE).withSrcAddress(ipv4Addr).withGrpMaskLength(UNIQUE_BYTE).withGrpAddress(ipv4Addr).build();
    }
    if (type.equals(TRAFFIC_ENGINEERING_ADDRESS.type())) {
        LispTeAddress.TeRecord tr = new LispTeAddress.TeRecord.Builder().withIsLookup(UNIQUE_BOOLEAN).withIsRlocProbe(UNIQUE_BOOLEAN).withIsStrict(UNIQUE_BOOLEAN).withRtrRlocAddress(ipv4Addr).build();
        address = new LispTeAddress.Builder().withTeRecords(ImmutableList.of(tr)).build();
    }
    if (type.equals(SOURCE_DEST_ADDRESS.type())) {
        address = new LispSrcDstAddress.Builder().withSrcMaskLength(UNIQUE_BYTE).withSrcPrefix(ipv4Addr).withDstMaskLength(UNIQUE_BYTE).withDstPrefix(ipv4Addr).build();
    }
    return address;
}
Also used : LispTeRecord(org.onosproject.lisp.msg.types.lcaf.LispTeRecord) ExtensionMappingAddress(org.onosproject.mapping.addresses.ExtensionMappingAddress) MappingAddress(org.onosproject.mapping.addresses.MappingAddress) ExtensionMappingAddress(org.onosproject.mapping.addresses.ExtensionMappingAddress)

Example 2 with ExtensionMappingAddress

use of org.onosproject.mapping.addresses.ExtensionMappingAddress in project onos by opennetworkinglab.

the class LispExtensionMappingAddressInterpreterTest method testAddressDecode.

/**
 * Tests decoding of an ExtensionMappingAddress JSON object.
 */
@Test
public void testAddressDecode() throws IOException {
    List<ExtensionMappingAddress> addresses = getLispExtensionMappingAddresses("LispExtensionMappingAddress.json");
    new EqualsTester().addEqualityGroup(addresses.get(0), listExtAddress).addEqualityGroup(addresses.get(1), segmentExtAddress).addEqualityGroup(addresses.get(2), asExtAddress).addEqualityGroup(addresses.get(3), appDataExtAddress).addEqualityGroup(addresses.get(4), gcExtAddress).addEqualityGroup(addresses.get(5), natExtAddress).addEqualityGroup(addresses.get(6), nonceExtAddress).addEqualityGroup(addresses.get(7), multicastExtAddress).addEqualityGroup(addresses.get(8), teExtAddress).addEqualityGroup(addresses.get(9), srcDstExtAddress).testEquals();
}
Also used : EqualsTester(com.google.common.testing.EqualsTester) ExtensionMappingAddress(org.onosproject.mapping.addresses.ExtensionMappingAddress) LispSrcDstAddressCodecTest(org.onosproject.drivers.lisp.extensions.codec.LispSrcDstAddressCodecTest) LispGcAddressCodecTest(org.onosproject.drivers.lisp.extensions.codec.LispGcAddressCodecTest) LispTeAddressCodecTest(org.onosproject.drivers.lisp.extensions.codec.LispTeAddressCodecTest) LispSegmentAddressCodecTest(org.onosproject.drivers.lisp.extensions.codec.LispSegmentAddressCodecTest) LispListAddressCodecTest(org.onosproject.drivers.lisp.extensions.codec.LispListAddressCodecTest) LispMulticastAddressCodecTest(org.onosproject.drivers.lisp.extensions.codec.LispMulticastAddressCodecTest) LispAsAddressCodecTest(org.onosproject.drivers.lisp.extensions.codec.LispAsAddressCodecTest) Test(org.junit.Test) LispAppDataAddressCodecTest(org.onosproject.drivers.lisp.extensions.codec.LispAppDataAddressCodecTest) LispNonceAddressCodecTest(org.onosproject.drivers.lisp.extensions.codec.LispNonceAddressCodecTest) LispNatAddressCodecTest(org.onosproject.drivers.lisp.extensions.codec.LispNatAddressCodecTest)

Example 3 with ExtensionMappingAddress

use of org.onosproject.mapping.addresses.ExtensionMappingAddress in project onos by opennetworkinglab.

the class LispExtensionMappingAddressInterpreterTest method getLispExtensionMappingAddresses.

/**
 * Reads in a collection of LispExtensionMappingAddresses from the given resource and decodes it.
 *
 * @param resourceName resource to use to read the JSON for the rule
 * @return decoded LispExtensionMappingAddresses
 * @throws IOException if processing the resource fails
 */
private List<ExtensionMappingAddress> getLispExtensionMappingAddresses(String resourceName) throws IOException {
    InputStream jsonStream = LispExtensionMappingAddressInterpreterTest.class.getResourceAsStream(resourceName);
    JsonNode json = context.mapper().readTree(jsonStream);
    assertThat("JSON string should not be null", json, notNullValue());
    final List<ExtensionMappingAddress> addresses = Lists.newArrayList();
    for (int addrIndex = 0; addrIndex < json.size(); addrIndex++) {
        ExtensionMappingAddress address = interpreter.decode(json.get(addrIndex).deepCopy(), context);
        assertThat("decoded address should not be null", address, notNullValue());
        addresses.add(address);
    }
    return addresses;
}
Also used : InputStream(java.io.InputStream) JsonNode(com.fasterxml.jackson.databind.JsonNode) ExtensionMappingAddress(org.onosproject.mapping.addresses.ExtensionMappingAddress)

Example 4 with ExtensionMappingAddress

use of org.onosproject.mapping.addresses.ExtensionMappingAddress in project onos by opennetworkinglab.

the class LispExtensionMappingAddressInterpreter method mapLcafAddress.

@Override
public ExtensionMappingAddress mapLcafAddress(LispLcafAddress lcafAddress) {
    switch(lcafAddress.getType()) {
        case LIST:
            LispListLcafAddress lcafListAddress = (LispListLcafAddress) lcafAddress;
            MappingAddress ipv4Ma = afi2mapping(lcafListAddress.getAddresses().get(0));
            MappingAddress ipv6Ma = afi2mapping(lcafListAddress.getAddresses().get(1));
            return new LispListAddress.Builder().withIpv4(ipv4Ma).withIpv6(ipv6Ma).build();
        case SEGMENT:
            LispSegmentLcafAddress segmentLcafAddress = (LispSegmentLcafAddress) lcafAddress;
            return new LispSegmentAddress.Builder().withInstanceId(segmentLcafAddress.getInstanceId()).withAddress(getMappingAddress(segmentLcafAddress.getAddress())).build();
        case AS:
            LispAsLcafAddress asLcafAddress = (LispAsLcafAddress) lcafAddress;
            return new org.onosproject.drivers.lisp.extensions.LispAsAddress.Builder().withAsNumber(asLcafAddress.getAsNumber()).withAddress(getMappingAddress(asLcafAddress.getAddress())).build();
        case APPLICATION_DATA:
            LispAppDataLcafAddress appLcafAddress = (LispAppDataLcafAddress) lcafAddress;
            return new LispAppDataAddress.Builder().withProtocol(appLcafAddress.getProtocol()).withIpTos(appLcafAddress.getIpTos()).withLocalPortLow(appLcafAddress.getLocalPortLow()).withLocalPortHigh(appLcafAddress.getLocalPortHigh()).withRemotePortLow(appLcafAddress.getRemotePortLow()).withRemotePortHigh(appLcafAddress.getRemotePortHigh()).withAddress(getMappingAddress(appLcafAddress.getAddress())).build();
        case GEO_COORDINATE:
            LispGeoCoordinateLcafAddress gcLcafAddress = (LispGeoCoordinateLcafAddress) lcafAddress;
            return new LispGcAddress.Builder().withIsNorth(gcLcafAddress.isNorth()).withLatitudeDegree(gcLcafAddress.getLatitudeDegree()).withLatitudeMinute(gcLcafAddress.getLatitudeMinute()).withLatitudeSecond(gcLcafAddress.getLatitudeSecond()).withIsEast(gcLcafAddress.isEast()).withLongitudeDegree(gcLcafAddress.getLongitudeDegree()).withLongitudeMinute(gcLcafAddress.getLongitudeMinute()).withLongitudeSecond(gcLcafAddress.getLongitudeSecond()).withAltitude(gcLcafAddress.getAltitude()).withAddress(getMappingAddress(gcLcafAddress.getAddress())).build();
        case NAT:
            LispNatLcafAddress natLcafAddress = (LispNatLcafAddress) lcafAddress;
            List<MappingAddress> mas = Lists.newArrayList();
            natLcafAddress.getRtrRlocAddresses().forEach(rtr -> mas.add(getMappingAddress(rtr)));
            return new LispNatAddress.Builder().withMsUdpPortNumber(natLcafAddress.getMsUdpPortNumber()).withEtrUdpPortNumber(natLcafAddress.getEtrUdpPortNumber()).withMsRlocAddress(getMappingAddress(natLcafAddress.getMsRlocAddress())).withGlobalEtrRlocAddress(getMappingAddress(natLcafAddress.getGlobalEtrRlocAddress())).withPrivateEtrRlocAddress(getMappingAddress(natLcafAddress.getPrivateEtrRlocAddress())).withRtrRlocAddresses(mas).build();
        case NONCE:
            LispNonceLcafAddress nonceLcafAddress = (LispNonceLcafAddress) lcafAddress;
            return new LispNonceAddress.Builder().withNonce(nonceLcafAddress.getNonce()).withAddress(getMappingAddress(nonceLcafAddress.getAddress())).build();
        case MULTICAST:
            LispMulticastLcafAddress multiLcafAddress = (LispMulticastLcafAddress) lcafAddress;
            return new LispMulticastAddress.Builder().withInstanceId(multiLcafAddress.getInstanceId()).withSrcAddress(getMappingAddress(multiLcafAddress.getSrcAddress())).withSrcMaskLength(multiLcafAddress.getSrcMaskLength()).withGrpAddress(getMappingAddress(multiLcafAddress.getGrpAddress())).withGrpMaskLength(multiLcafAddress.getGrpMaskLength()).build();
        case TRAFFIC_ENGINEERING:
            LispTeLcafAddress teLcafAddress = (LispTeLcafAddress) lcafAddress;
            List<LispTeAddress.TeRecord> records = Lists.newArrayList();
            teLcafAddress.getTeRecords().forEach(record -> {
                LispTeAddress.TeRecord teRecord = new LispTeAddress.TeRecord.Builder().withIsLookup(record.isLookup()).withIsRlocProbe(record.isRlocProbe()).withIsStrict(record.isStrict()).withRtrRlocAddress(getMappingAddress(record.getRtrRlocAddress())).build();
                records.add(teRecord);
            });
            return new LispTeAddress.Builder().withTeRecords(records).build();
        case SECURITY:
            // TODO: need to implement security type later
            log.warn("security type will be implemented later");
            return null;
        case SOURCE_DEST:
            LispSourceDestLcafAddress srcDstLcafAddress = (LispSourceDestLcafAddress) lcafAddress;
            return new LispSrcDstAddress.Builder().withSrcPrefix(getMappingAddress(srcDstLcafAddress.getSrcPrefix())).withSrcMaskLength(srcDstLcafAddress.getSrcMaskLength()).withDstPrefix(getMappingAddress(srcDstLcafAddress.getDstPrefix())).withDstMaskLength(srcDstLcafAddress.getDstMaskLength()).build();
        case UNSPECIFIED:
        case UNKNOWN:
        default:
            log.error("Unsupported LCAF type {}", lcafAddress.getType());
            return null;
    }
}
Also used : LispMulticastLcafAddress(org.onosproject.lisp.msg.types.lcaf.LispMulticastLcafAddress) LispNatLcafAddress(org.onosproject.lisp.msg.types.lcaf.LispNatLcafAddress) LispNonceLcafAddress(org.onosproject.lisp.msg.types.lcaf.LispNonceLcafAddress) LispTeLcafAddress(org.onosproject.lisp.msg.types.lcaf.LispTeLcafAddress) LispTeRecord(org.onosproject.lisp.msg.types.lcaf.LispTeRecord) LispListLcafAddress(org.onosproject.lisp.msg.types.lcaf.LispListLcafAddress) LispAsLcafAddress(org.onosproject.lisp.msg.types.lcaf.LispAsLcafAddress) LispGeoCoordinateLcafAddress(org.onosproject.lisp.msg.types.lcaf.LispGeoCoordinateLcafAddress) ExtensionMappingAddress(org.onosproject.mapping.addresses.ExtensionMappingAddress) IPMappingAddress(org.onosproject.mapping.addresses.IPMappingAddress) MappingAddress(org.onosproject.mapping.addresses.MappingAddress) LispSegmentLcafAddress(org.onosproject.lisp.msg.types.lcaf.LispSegmentLcafAddress) LispAppDataLcafAddress(org.onosproject.lisp.msg.types.lcaf.LispAppDataLcafAddress) LispSourceDestLcafAddress(org.onosproject.lisp.msg.types.lcaf.LispSourceDestLcafAddress)

Example 5 with ExtensionMappingAddress

use of org.onosproject.mapping.addresses.ExtensionMappingAddress in project onos by opennetworkinglab.

the class MappingAddressBuilder method lcaf2extension.

/**
 * Converts LCAF address to extension mapping address.
 *
 * @param deviceService device service
 * @param deviceId      device identifier
 * @param lcaf          LCAF address
 * @return extension mapping address
 */
private static MappingAddress lcaf2extension(DeviceService deviceService, DeviceId deviceId, LispLcafAddress lcaf) {
    Device device = deviceService.getDevice(deviceId);
    ExtensionMappingAddressInterpreter addressInterpreter;
    ExtensionMappingAddress mappingAddress = null;
    if (device.is(ExtensionMappingAddressInterpreter.class)) {
        addressInterpreter = device.as(ExtensionMappingAddressInterpreter.class);
    } else {
        addressInterpreter = null;
    }
    switch(lcaf.getType()) {
        case LIST:
            if (addressInterpreter != null && addressInterpreter.supported(LIST_ADDRESS.type())) {
                mappingAddress = addressInterpreter.mapLcafAddress(lcaf);
            }
            break;
        case SEGMENT:
            if (addressInterpreter != null && addressInterpreter.supported(SEGMENT_ADDRESS.type())) {
                mappingAddress = addressInterpreter.mapLcafAddress(lcaf);
            }
            break;
        case AS:
            if (addressInterpreter != null && addressInterpreter.supported(AS_ADDRESS.type())) {
                mappingAddress = addressInterpreter.mapLcafAddress(lcaf);
            }
            break;
        case APPLICATION_DATA:
            if (addressInterpreter != null && addressInterpreter.supported(APPLICATION_DATA_ADDRESS.type())) {
                mappingAddress = addressInterpreter.mapLcafAddress(lcaf);
            }
            break;
        case GEO_COORDINATE:
            if (addressInterpreter != null && addressInterpreter.supported(GEO_COORDINATE_ADDRESS.type())) {
                mappingAddress = addressInterpreter.mapLcafAddress(lcaf);
            }
            break;
        case NAT:
            if (addressInterpreter != null && addressInterpreter.supported(NAT_ADDRESS.type())) {
                mappingAddress = addressInterpreter.mapLcafAddress(lcaf);
            }
            break;
        case NONCE:
            if (addressInterpreter != null && addressInterpreter.supported(NONCE_ADDRESS.type())) {
                mappingAddress = addressInterpreter.mapLcafAddress(lcaf);
            }
            break;
        case MULTICAST:
            if (addressInterpreter != null && addressInterpreter.supported(MULTICAST_ADDRESS.type())) {
                mappingAddress = addressInterpreter.mapLcafAddress(lcaf);
            }
            break;
        case TRAFFIC_ENGINEERING:
            if (addressInterpreter != null && addressInterpreter.supported(TRAFFIC_ENGINEERING_ADDRESS.type())) {
                mappingAddress = addressInterpreter.mapLcafAddress(lcaf);
            }
            break;
        case SOURCE_DEST:
            if (addressInterpreter != null && addressInterpreter.supported(SOURCE_DEST_ADDRESS.type())) {
                mappingAddress = addressInterpreter.mapLcafAddress(lcaf);
            }
            break;
        default:
            log.warn("Unsupported extension mapping address type {}", lcaf.getType());
            break;
    }
    return mappingAddress != null ? MappingAddresses.extensionMappingAddressWrapper(mappingAddress, deviceId) : null;
}
Also used : Device(org.onosproject.net.Device) ExtensionMappingAddressInterpreter(org.onosproject.lisp.ctl.ExtensionMappingAddressInterpreter) ExtensionMappingAddress(org.onosproject.mapping.addresses.ExtensionMappingAddress)

Aggregations

ExtensionMappingAddress (org.onosproject.mapping.addresses.ExtensionMappingAddress)5 LispTeRecord (org.onosproject.lisp.msg.types.lcaf.LispTeRecord)2 MappingAddress (org.onosproject.mapping.addresses.MappingAddress)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 EqualsTester (com.google.common.testing.EqualsTester)1 InputStream (java.io.InputStream)1 Test (org.junit.Test)1 LispAppDataAddressCodecTest (org.onosproject.drivers.lisp.extensions.codec.LispAppDataAddressCodecTest)1 LispAsAddressCodecTest (org.onosproject.drivers.lisp.extensions.codec.LispAsAddressCodecTest)1 LispGcAddressCodecTest (org.onosproject.drivers.lisp.extensions.codec.LispGcAddressCodecTest)1 LispListAddressCodecTest (org.onosproject.drivers.lisp.extensions.codec.LispListAddressCodecTest)1 LispMulticastAddressCodecTest (org.onosproject.drivers.lisp.extensions.codec.LispMulticastAddressCodecTest)1 LispNatAddressCodecTest (org.onosproject.drivers.lisp.extensions.codec.LispNatAddressCodecTest)1 LispNonceAddressCodecTest (org.onosproject.drivers.lisp.extensions.codec.LispNonceAddressCodecTest)1 LispSegmentAddressCodecTest (org.onosproject.drivers.lisp.extensions.codec.LispSegmentAddressCodecTest)1 LispSrcDstAddressCodecTest (org.onosproject.drivers.lisp.extensions.codec.LispSrcDstAddressCodecTest)1 LispTeAddressCodecTest (org.onosproject.drivers.lisp.extensions.codec.LispTeAddressCodecTest)1 ExtensionMappingAddressInterpreter (org.onosproject.lisp.ctl.ExtensionMappingAddressInterpreter)1 LispAppDataLcafAddress (org.onosproject.lisp.msg.types.lcaf.LispAppDataLcafAddress)1 LispAsLcafAddress (org.onosproject.lisp.msg.types.lcaf.LispAsLcafAddress)1