Search in sources :

Example 6 with MappingTreatment

use of org.onosproject.mapping.MappingTreatment in project onos by opennetworkinglab.

the class MappingValueCodecTest method testMappingValueEncode.

/**
 * Tests encoding of a mapping value object.
 */
@Test
public void testMappingValueEncode() {
    MappingInstruction unicastWeight = MappingInstructions.unicastWeight(UNICAST_WEIGHT);
    MappingInstruction unicastPriority = MappingInstructions.unicastPriority(UNICAST_PRIORITY);
    MappingInstruction multicastWeight = MappingInstructions.multicastWeight(MULTICAST_WEIGHT);
    MappingInstruction multicastPriority = MappingInstructions.multicastPriority(MULTICAST_PRIORITY);
    MappingAddress address = MappingAddresses.ipv4MappingAddress(IPV4_PREFIX);
    MappingTreatment treatment = DefaultMappingTreatment.builder().add(unicastWeight).add(unicastPriority).add(multicastWeight).add(multicastPriority).withAddress(address).build();
    MappingAction action = MappingActions.noAction();
    MappingValue value = DefaultMappingValue.builder().add(treatment).withAction(action).build();
    ObjectNode valueJson = valueCodec.encode(value, context);
    assertThat(valueJson, MappingValueJsonMatcher.matchesMappingValue(value));
}
Also used : MappingAddress(org.onosproject.mapping.addresses.MappingAddress) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MappingAction(org.onosproject.mapping.actions.MappingAction) 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) Test(org.junit.Test)

Example 7 with MappingTreatment

use of org.onosproject.mapping.MappingTreatment 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 8 with MappingTreatment

use of org.onosproject.mapping.MappingTreatment in project onos by opennetworkinglab.

the class MappingEntryCodecTest method testMappingEntryEncode.

/**
 * Tests encoding of a mapping entry object.
 */
@Test
public void testMappingEntryEncode() {
    MappingAddress address = MappingAddresses.ipv4MappingAddress(IPV4_PREFIX);
    MappingInstruction unicastWeight = MappingInstructions.unicastWeight(UNICAST_WEIGHT);
    MappingInstruction unicastPriority = MappingInstructions.unicastPriority(UNICAST_PRIORITY);
    MappingInstruction multicastWeight = MappingInstructions.multicastWeight(MULTICAST_WEIGHT);
    MappingInstruction multicastPriority = MappingInstructions.multicastPriority(MULTICAST_PRIORITY);
    MappingKey key = DefaultMappingKey.builder().withAddress(address).build();
    MappingTreatment treatment = DefaultMappingTreatment.builder().add(unicastWeight).add(unicastPriority).add(multicastWeight).add(multicastPriority).withAddress(address).build();
    MappingAction action = MappingActions.noAction();
    MappingValue value = DefaultMappingValue.builder().add(treatment).withAction(action).build();
    Mapping mapping = DefaultMapping.builder().withId(ID).forDevice(DEVICE_ID).withKey(key).withValue(value).build();
    MappingEntry entry = new DefaultMappingEntry(mapping, STATE);
    ObjectNode entryJson = entryCodec.encode(entry, context);
    assertThat(entryJson, MappingEntryJsonMatcher.matchesMappingEntry(entry));
}
Also used : MappingEntry(org.onosproject.mapping.MappingEntry) DefaultMappingEntry(org.onosproject.mapping.DefaultMappingEntry) MappingAddress(org.onosproject.mapping.addresses.MappingAddress) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MappingAction(org.onosproject.mapping.actions.MappingAction) 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) MappingInstruction(org.onosproject.mapping.instructions.MappingInstruction) Test(org.junit.Test)

Example 9 with MappingTreatment

use of org.onosproject.mapping.MappingTreatment in project onos by opennetworkinglab.

the class MappingTreatmentCodecTest method getTreatment.

/**
 * Reads in a mapping treatment from the given resource and decodes it.
 *
 * @param resourceName resource to use to read the JSON for the rule
 * @return decoded mappingTreatment
 * @throws IOException if processing the resource fails
 */
private MappingTreatment getTreatment(String resourceName) throws IOException {
    InputStream jsonStream = MappingTreatmentCodecTest.class.getResourceAsStream(resourceName);
    JsonNode json = context.mapper().readTree(jsonStream);
    assertThat(json, notNullValue());
    MappingTreatment treatment = treatmentCodec.decode((ObjectNode) json, context);
    assertThat(treatment, notNullValue());
    return treatment;
}
Also used : InputStream(java.io.InputStream) JsonNode(com.fasterxml.jackson.databind.JsonNode) MappingTreatment(org.onosproject.mapping.MappingTreatment) DefaultMappingTreatment(org.onosproject.mapping.DefaultMappingTreatment)

Example 10 with MappingTreatment

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

Aggregations

MappingTreatment (org.onosproject.mapping.MappingTreatment)12 DefaultMappingTreatment (org.onosproject.mapping.DefaultMappingTreatment)9 MappingAddress (org.onosproject.mapping.addresses.MappingAddress)7 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)6 MappingValue (org.onosproject.mapping.MappingValue)6 MappingAction (org.onosproject.mapping.actions.MappingAction)6 MappingInstruction (org.onosproject.mapping.instructions.MappingInstruction)6 DefaultMappingValue (org.onosproject.mapping.DefaultMappingValue)5 Test (org.junit.Test)4 MappingKey (org.onosproject.mapping.MappingKey)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 DefaultMappingKey (org.onosproject.mapping.DefaultMappingKey)3 MappingEntry (org.onosproject.mapping.MappingEntry)3 DefaultMapping (org.onosproject.mapping.DefaultMapping)2 DefaultMappingEntry (org.onosproject.mapping.DefaultMappingEntry)2 Mapping (org.onosproject.mapping.Mapping)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 InputStream (java.io.InputStream)1 Before (org.junit.Before)1 IpPrefix (org.onlab.packet.IpPrefix)1