Search in sources :

Example 61 with MappingAddress

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

the class DistributedMappingStoreTest method setUp.

/**
 * Sets up the storage service test harness.
 */
@Before
public void setUp() {
    mappingStore = new DistributedMappingStore();
    mappingStore.storageService = new TestStorageService();
    mappingStore.deviceService = new InternalDeviceServiceAdapter();
    mappingStore.setDelegate(event -> {
    });
    IpPrefix ipPrefix = IpPrefix.valueOf(IP_ADDRESS);
    MappingAddress address = MappingAddresses.ipv4MappingAddress(ipPrefix);
    MappingKey key = DefaultMappingKey.builder().withAddress(address).build();
    MappingAction action = MappingActions.noAction();
    MappingTreatment treatment = DefaultMappingTreatment.builder().withAddress(address).setUnicastPriority(10).setUnicastWeight(10).build();
    MappingValue value = DefaultMappingValue.builder().withAction(action).add(treatment).build();
    device1 = new MockDevice(ProviderId.NONE, DEVICE_ID_1, Device.Type.OTHER, "foo.inc", "0", "0", "0", null, DefaultAnnotations.builder().build());
    device2 = new MockDevice(ProviderId.NONE, DEVICE_ID_2, Device.Type.OTHER, "foo.inc", "0", "0", "0", null, DefaultAnnotations.builder().build());
    Mapping originalMapping1 = DefaultMapping.builder().forDevice(DEVICE_ID_1).withId(1000L).withKey(key).withValue(value).build();
    Mapping originalMapping2 = DefaultMapping.builder().forDevice(DEVICE_ID_2).withId(2000L).withKey(key).withValue(value).build();
    mapping1 = new DefaultMappingEntry(originalMapping1);
    mapping2 = new DefaultMappingEntry(originalMapping2);
    mappingStore.activate();
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) MappingAddress(org.onosproject.mapping.addresses.MappingAddress) MappingAction(org.onosproject.mapping.actions.MappingAction) TestStorageService(org.onosproject.store.service.TestStorageService) DefaultMapping(org.onosproject.mapping.DefaultMapping) Mapping(org.onosproject.mapping.Mapping) DefaultMappingEntry(org.onosproject.mapping.DefaultMappingEntry) 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) Before(org.junit.Before)

Example 62 with MappingAddress

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

the class MappingKeyCodec method decode.

@Override
public MappingKey decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    MappingKey.Builder builder = DefaultMappingKey.builder();
    ObjectNode addressJson = get(json, ADDRESS);
    if (addressJson != null) {
        final JsonCodec<MappingAddress> addressCodec = context.codec(MappingAddress.class);
        builder.withAddress(addressCodec.decode(addressJson, context));
    }
    return builder.build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MappingAddress(org.onosproject.mapping.addresses.MappingAddress) MappingKey(org.onosproject.mapping.MappingKey) DefaultMappingKey(org.onosproject.mapping.DefaultMappingKey)

Example 63 with MappingAddress

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

the class MappingTreatmentCodec method decode.

@Override
public MappingTreatment decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    final JsonCodec<MappingInstruction> instructionCodec = context.codec(MappingInstruction.class);
    JsonNode instructionJson = json.get(INSTRUCTIONS);
    MappingTreatment.Builder builder = DefaultMappingTreatment.builder();
    if (instructionJson != null) {
        IntStream.range(0, instructionJson.size()).forEach(i -> builder.add(instructionCodec.decode(get(instructionJson, i), context)));
    }
    ObjectNode addressJson = get(json, ADDRESS);
    if (addressJson != null) {
        final JsonCodec<MappingAddress> addressCodec = context.codec(MappingAddress.class);
        builder.withAddress(addressCodec.decode(addressJson, context));
    }
    return builder.build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MappingAddress(org.onosproject.mapping.addresses.MappingAddress) JsonNode(com.fasterxml.jackson.databind.JsonNode) DefaultMappingTreatment(org.onosproject.mapping.DefaultMappingTreatment) MappingTreatment(org.onosproject.mapping.MappingTreatment) MappingInstruction(org.onosproject.mapping.instructions.MappingInstruction)

Example 64 with MappingAddress

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

the class MappingTreatmentCodec method encode.

@Override
public ObjectNode encode(MappingTreatment treatment, CodecContext context) {
    checkNotNull(treatment, "Mapping treatment cannot be null");
    final ObjectNode result = context.mapper().createObjectNode();
    final ArrayNode jsonInstructions = result.putArray(INSTRUCTIONS);
    final JsonCodec<MappingInstruction> instructionCodec = context.codec(MappingInstruction.class);
    final JsonCodec<MappingAddress> addressCodec = context.codec(MappingAddress.class);
    for (final MappingInstruction instruction : treatment.instructions()) {
        jsonInstructions.add(instructionCodec.encode(instruction, context));
    }
    result.set(ADDRESS, addressCodec.encode(treatment.address(), context));
    return result;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MappingAddress(org.onosproject.mapping.addresses.MappingAddress) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) MappingInstruction(org.onosproject.mapping.instructions.MappingInstruction)

Example 65 with MappingAddress

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

the class DefaultMappingTreatmentTest method testEquals.

/**
 * Tests equals() method.
 */
@Test
public void testEquals() {
    IpPrefix ip1 = IpPrefix.valueOf(IP_ADDRESS_1);
    MappingAddress address1 = MappingAddresses.ipv4MappingAddress(ip1);
    MappingTreatment treatment1 = DefaultMappingTreatment.builder().withAddress(address1).setUnicastPriority(10).setUnicastWeight(10).build();
    MappingTreatment sameAsTreatment1 = DefaultMappingTreatment.builder().withAddress(address1).setUnicastPriority(10).setUnicastWeight(10).build();
    IpPrefix ip2 = IpPrefix.valueOf(IP_ADDRESS_2);
    MappingAddress address2 = MappingAddresses.ipv4MappingAddress(ip2);
    MappingTreatment treatment2 = DefaultMappingTreatment.builder().withAddress(address2).setMulticastPriority(20).setMulticastWeight(20).build();
    new EqualsTester().addEqualityGroup(treatment1, sameAsTreatment1).addEqualityGroup(treatment2).testEquals();
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) MappingAddress(org.onosproject.mapping.addresses.MappingAddress) EqualsTester(com.google.common.testing.EqualsTester) 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