Search in sources :

Example 31 with MappingAddress

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

the class DefaultMappingTreatmentTest method testBuilderMethods.

/**
 * Tests method defined on the Builder.
 */
@Test
public void testBuilderMethods() {
    IpPrefix ip = IpPrefix.valueOf(IP_ADDRESS_1);
    MappingAddress address = MappingAddresses.ipv4MappingAddress(ip);
    MappingTreatment.Builder builder = DefaultMappingTreatment.builder().withAddress(address).setUnicastPriority(10).setUnicastWeight(10);
    MappingTreatment treatment = builder.build();
    assertThat(treatment.instructions(), hasSize(2));
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) MappingAddress(org.onosproject.mapping.addresses.MappingAddress) Test(org.junit.Test)

Example 32 with MappingAddress

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

the class MappingKeyCodec method encode.

@Override
public ObjectNode encode(MappingKey key, CodecContext context) {
    checkNotNull(key, "Mapping key cannot be null");
    final ObjectNode result = context.mapper().createObjectNode();
    final JsonCodec<MappingAddress> addressCodec = context.codec(MappingAddress.class);
    result.set(ADDRESS, addressCodec.encode(key.address(), context));
    return result;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MappingAddress(org.onosproject.mapping.addresses.MappingAddress)

Example 33 with MappingAddress

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

the class MappingsWebResourceTest method setupMockMappings.

/**
 * Populates some mappings used as testing data.
 */
private void setupMockMappings() {
    MappingAddress address1 = MappingAddresses.ipv4MappingAddress(IPV4_PREFIX_1);
    MappingAddress address2 = MappingAddresses.ipv4MappingAddress(IPV4_PREFIX_2);
    MappingInstruction unicastWeight1 = unicastWeight(UNICAST_WEIGHT);
    MappingInstruction unicastPriority1 = unicastPriority(UNICAST_PRIORITY);
    MappingInstruction multicastWeight1 = multicastWeight(MULTICAST_WEIGHT);
    MappingInstruction multicastPriority1 = multicastPriority(MULTICAST_PRIORITY);
    MappingInstruction unicastWeight2 = unicastWeight(UNICAST_WEIGHT + DIFF_VALUE);
    MappingInstruction unicastPriority2 = unicastPriority(UNICAST_PRIORITY + DIFF_VALUE);
    MappingInstruction multicastWeight2 = multicastWeight(MULTICAST_WEIGHT + DIFF_VALUE);
    MappingInstruction multicastPriority2 = multicastPriority(MULTICAST_PRIORITY + DIFF_VALUE);
    MappingKey key1 = DefaultMappingKey.builder().withAddress(address1).build();
    MappingTreatment treatment1 = DefaultMappingTreatment.builder().add(unicastWeight1).add(unicastPriority1).add(multicastWeight1).add(multicastPriority1).withAddress(address1).build();
    MappingAction action1 = MappingActions.noAction();
    MappingValue value1 = DefaultMappingValue.builder().add(treatment1).withAction(action1).build();
    MappingKey key2 = DefaultMappingKey.builder().withAddress(address2).build();
    MappingTreatment treatment2 = DefaultMappingTreatment.builder().add(unicastWeight2).add(unicastPriority2).add(multicastWeight2).add(multicastPriority2).withAddress(address2).build();
    MappingAction action2 = MappingActions.forward();
    MappingValue value2 = DefaultMappingValue.builder().add(treatment2).withAction(action2).build();
    mapping1.key = key1;
    mapping2.key = key2;
    mapping3.key = key1;
    mapping4.key = key2;
    mapping1.value = value1;
    mapping2.value = value2;
    mapping3.value = value1;
    mapping4.value = value2;
    final Set<MappingEntry> mappings1 = Sets.newHashSet();
    mappings1.add(mapping1);
    mappings1.add(mapping2);
    final Set<MappingEntry> mappings2 = Sets.newHashSet();
    mappings2.add(mapping3);
    mappings2.add(mapping4);
    mappings.put(deviceId1, mappings1);
    mappings.put(deviceId2, mappings2);
}
Also used : MappingEntry(org.onosproject.mapping.MappingEntry) MappingAddress(org.onosproject.mapping.addresses.MappingAddress) MappingAction(org.onosproject.mapping.actions.MappingAction) DefaultMappingKey(org.onosproject.mapping.DefaultMappingKey) MappingKey(org.onosproject.mapping.MappingKey) MappingTreatment(org.onosproject.mapping.MappingTreatment) DefaultMappingTreatment(org.onosproject.mapping.DefaultMappingTreatment) DefaultMappingValue(org.onosproject.mapping.DefaultMappingValue) MappingValue(org.onosproject.mapping.MappingValue) MappingInstruction(org.onosproject.mapping.instructions.MappingInstruction)

Example 34 with MappingAddress

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

the class MappingEntryBuilder method buildTreatments.

/**
 * Builds a collection of mapping treatments.
 *
 * @param record LISP map record
 * @return a collection of mapping treatments
 */
private List<MappingTreatment> buildTreatments(LispMapRecord record) {
    List<LispLocator> locators = record.getLocators();
    List<MappingTreatment> treatments = Lists.newArrayList();
    for (LispLocator locator : locators) {
        MappingTreatment.Builder builder = DefaultMappingTreatment.builder();
        LispAfiAddress address = locator.getLocatorAfi();
        final MappingAddress mappingAddress = getAddress(deviceService, deviceId, address);
        if (mappingAddress != null) {
            builder.withAddress(mappingAddress);
        }
        builder.setUnicastWeight(locator.getWeight()).setUnicastPriority(locator.getPriority()).setMulticastWeight(locator.getMulticastWeight()).setMulticastPriority(locator.getMulticastPriority());
        // TODO: need to convert specific properties to
        // abstracted extension properties
        treatments.add(builder.build());
    }
    return treatments;
}
Also used : MappingAddress(org.onosproject.mapping.addresses.MappingAddress) LispLocator(org.onosproject.lisp.msg.protocols.LispLocator) LispAfiAddress(org.onosproject.lisp.msg.types.LispAfiAddress) MappingTreatment(org.onosproject.mapping.MappingTreatment) DefaultMappingTreatment(org.onosproject.mapping.DefaultMappingTreatment)

Example 35 with MappingAddress

use of org.onosproject.mapping.addresses.MappingAddress 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)

Aggregations

MappingAddress (org.onosproject.mapping.addresses.MappingAddress)66 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)34 Test (org.junit.Test)26 Before (org.junit.Before)11 DefaultMappingTreatment (org.onosproject.mapping.DefaultMappingTreatment)7 MappingTreatment (org.onosproject.mapping.MappingTreatment)7 MappingAddressJsonMatcher.matchesMappingAddress (org.onosproject.mapping.codec.MappingAddressJsonMatcher.matchesMappingAddress)7 IpPrefix (org.onlab.packet.IpPrefix)6 MappingInstruction (org.onosproject.mapping.instructions.MappingInstruction)6 DefaultMappingKey (org.onosproject.mapping.DefaultMappingKey)5 MappingKey (org.onosproject.mapping.MappingKey)5 DefaultMappingValue (org.onosproject.mapping.DefaultMappingValue)4 MappingValue (org.onosproject.mapping.MappingValue)4 MappingAction (org.onosproject.mapping.actions.MappingAction)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 EqualsTester (com.google.common.testing.EqualsTester)2 LispNatAddress (org.onosproject.drivers.lisp.extensions.LispNatAddress)2 LispTeRecord (org.onosproject.lisp.msg.types.lcaf.LispTeRecord)2 DefaultMapping (org.onosproject.mapping.DefaultMapping)2