Search in sources :

Example 6 with MappingAction

use of org.onosproject.mapping.actions.MappingAction 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 7 with MappingAction

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

use of org.onosproject.mapping.actions.MappingAction in project onos by opennetworkinglab.

the class DefaultMappingValueTest method testBuilderMethods.

/**
 * Tests methods defined on the Builder.
 */
@Test
public void testBuilderMethods() {
    MappingAction action = MappingActions.noAction();
    MappingTreatment treatment = DefaultMappingTreatment.builder().withAddress(ma1).setUnicastPriority(10).setUnicastWeight(10).build();
    MappingValue value = DefaultMappingValue.builder().withAction(action).add(treatment).build();
    assertThat(value.action(), is(action));
    assertThat(value.treatments(), hasSize(1));
}
Also used : MappingAction(org.onosproject.mapping.actions.MappingAction) Test(org.junit.Test)

Example 9 with MappingAction

use of org.onosproject.mapping.actions.MappingAction in project onos by opennetworkinglab.

the class MappingActionCodecTest method getAction.

/**
 * Reads in a mapping action from the given resource and decodes it.
 *
 * @param resourceName resource to use to read the JSON for the rule
 * @return decoded mappingAction
 * @throws IOException if processing the resource fails
 */
private MappingAction getAction(String resourceName) throws IOException {
    InputStream jsonStream = MappingActionCodecTest.class.getResourceAsStream(resourceName);
    JsonNode json = context.mapper().readTree(jsonStream);
    assertThat(json, notNullValue());
    MappingAction action = actionCodec.decode((ObjectNode) json, context);
    assertThat(action, notNullValue());
    return action;
}
Also used : MappingAction(org.onosproject.mapping.actions.MappingAction) NativeForwardMappingAction(org.onosproject.mapping.actions.NativeForwardMappingAction) DropMappingAction(org.onosproject.mapping.actions.DropMappingAction) ForwardMappingAction(org.onosproject.mapping.actions.ForwardMappingAction) NoMappingAction(org.onosproject.mapping.actions.NoMappingAction) InputStream(java.io.InputStream) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 10 with MappingAction

use of org.onosproject.mapping.actions.MappingAction in project onos by opennetworkinglab.

the class MappingValueCodec method encode.

@Override
public ObjectNode encode(MappingValue value, CodecContext context) {
    checkNotNull(value, "Mapping value cannot be null");
    final ObjectNode result = context.mapper().createObjectNode();
    final ArrayNode jsonTreatments = result.putArray(TREATMENTS);
    final JsonCodec<MappingTreatment> treatmentCodec = context.codec(MappingTreatment.class);
    final JsonCodec<MappingAction> actionCodec = context.codec(MappingAction.class);
    for (final MappingTreatment treatment : value.treatments()) {
        jsonTreatments.add(treatmentCodec.encode(treatment, context));
    }
    result.set(ACTION, actionCodec.encode(value.action(), context));
    return result;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MappingAction(org.onosproject.mapping.actions.MappingAction) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) MappingTreatment(org.onosproject.mapping.MappingTreatment)

Aggregations

MappingAction (org.onosproject.mapping.actions.MappingAction)10 MappingTreatment (org.onosproject.mapping.MappingTreatment)6 Test (org.junit.Test)5 DefaultMappingValue (org.onosproject.mapping.DefaultMappingValue)5 MappingValue (org.onosproject.mapping.MappingValue)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 DefaultMappingTreatment (org.onosproject.mapping.DefaultMappingTreatment)4 MappingAddress (org.onosproject.mapping.addresses.MappingAddress)4 DefaultMappingKey (org.onosproject.mapping.DefaultMappingKey)3 MappingKey (org.onosproject.mapping.MappingKey)3 MappingInstruction (org.onosproject.mapping.instructions.MappingInstruction)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 DefaultMapping (org.onosproject.mapping.DefaultMapping)2 DefaultMappingEntry (org.onosproject.mapping.DefaultMappingEntry)2 Mapping (org.onosproject.mapping.Mapping)2 MappingEntry (org.onosproject.mapping.MappingEntry)2 DropMappingAction (org.onosproject.mapping.actions.DropMappingAction)2 ForwardMappingAction (org.onosproject.mapping.actions.ForwardMappingAction)2 NativeForwardMappingAction (org.onosproject.mapping.actions.NativeForwardMappingAction)2 NoMappingAction (org.onosproject.mapping.actions.NoMappingAction)2