Search in sources :

Example 21 with MappingAddress

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

the class LispSrcDstAddressCodec method encode.

@Override
public ObjectNode encode(LispSrcDstAddress address, CodecContext context) {
    checkNotNull(address, "LispSrcDstAddress cannot be null");
    final JsonCodec<MappingAddress> addressCodec = context.codec(MappingAddress.class);
    final ObjectNode result = context.mapper().createObjectNode().put(SRC_MASK_LENGTH, address.getSrcMaskLength()).put(DST_MASK_LENGTH, address.getDstMaskLength());
    if (address.getSrcPrefix() != null) {
        ObjectNode srcPrefix = addressCodec.encode(address.getSrcPrefix(), context);
        result.set(SRC_PREFIX, srcPrefix);
    }
    if (address.getDstPrefix() != null) {
        ObjectNode dstPrefix = addressCodec.encode(address.getDstPrefix(), context);
        result.set(DST_PREFIX, dstPrefix);
    }
    return result;
}
Also used : MappingAddress(org.onosproject.mapping.addresses.MappingAddress) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode)

Example 22 with MappingAddress

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

the class LispTeRecordCodec method encode.

@Override
public ObjectNode encode(LispTeAddress.TeRecord record, CodecContext context) {
    checkNotNull(record, "LispTeRecord cannot be null");
    final ObjectNode result = context.mapper().createObjectNode().put(LOOKUP, record.isLookup()).put(RLOC_PROBE, record.isRlocProbe()).put(STRICT, record.isStrict());
    if (record.getAddress() != null) {
        final JsonCodec<MappingAddress> addressCodec = context.codec(MappingAddress.class);
        ObjectNode address = addressCodec.encode(record.getAddress(), context);
        result.set(ADDRESS, address);
    }
    return result;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MappingAddress(org.onosproject.mapping.addresses.MappingAddress)

Example 23 with MappingAddress

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

the class LispTeRecordCodec method decode.

@Override
public LispTeAddress.TeRecord decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    boolean isLookup = nullIsIllegal(json.get(LOOKUP), LOOKUP + MISSING_MEMBER_MESSAGE).asBoolean();
    boolean isRlocProbe = nullIsIllegal(json.get(RLOC_PROBE), RLOC_PROBE + MISSING_MEMBER_MESSAGE).asBoolean();
    boolean isStrict = nullIsIllegal(json.get(STRICT), STRICT + MISSING_MEMBER_MESSAGE).asBoolean();
    ObjectNode addressJson = get(json, ADDRESS);
    MappingAddress mappingAddress = null;
    if (addressJson != null) {
        final JsonCodec<MappingAddress> addressCodec = context.codec(MappingAddress.class);
        mappingAddress = addressCodec.decode(addressJson, context);
    }
    return new LispTeAddress.TeRecord.Builder().withIsLookup(isLookup).withIsRlocProbe(isRlocProbe).withIsStrict(isStrict).withRtrRlocAddress(mappingAddress).build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MappingAddress(org.onosproject.mapping.addresses.MappingAddress)

Example 24 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 25 with MappingAddress

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

the class DefaultMappingTreatmentTest method testIllegalUnicastTypeConstruction.

/**
 * Tests illegal unicast type instruction construction.
 */
@Test(expected = IllegalArgumentException.class)
public void testIllegalUnicastTypeConstruction() {
    IpPrefix ip = IpPrefix.valueOf(IP_ADDRESS_1);
    MappingAddress address = MappingAddresses.ipv4MappingAddress(ip);
    DefaultMappingTreatment.builder().withAddress(address).setUnicastPriority(10).setUnicastWeight(10).setUnicastPriority(20).build();
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) MappingAddress(org.onosproject.mapping.addresses.MappingAddress) Test(org.junit.Test)

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