Search in sources :

Example 1 with MappingEntry

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

the class MappingsWebResource method getMappingsByDeviceId.

/**
 * Gets mapping entries of a device. Returns array of all mappings for the
 * specified device.
 *
 * @param deviceId device identifier
 * @param type     mapping store type
 * @return 200 OK with a collection of mappings of given device
 *
 * @onos.rsModel MappingEntries
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{deviceId}/{type}")
public Response getMappingsByDeviceId(@PathParam("deviceId") String deviceId, @PathParam("type") String type) {
    Device device = deviceService.getDevice(DeviceId.deviceId(deviceId));
    if (device == null) {
        throw new ItemNotFoundException(DEVICE_NOT_FOUND);
    }
    final Iterable<MappingEntry> mappingEntries = mappingService.getMappingEntries(getTypeEnum(type), device.id());
    if (mappingEntries == null || !mappingEntries.iterator().hasNext()) {
        return ok(root).build();
    }
    for (final MappingEntry entry : mappingEntries) {
        mappingsNode.add(codec(MappingEntry.class).encode(entry, this));
    }
    return ok(root).build();
}
Also used : MappingEntry(org.onosproject.mapping.MappingEntry) Device(org.onosproject.net.Device) ItemNotFoundException(org.onlab.util.ItemNotFoundException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with MappingEntry

use of org.onosproject.mapping.MappingEntry 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 3 with MappingEntry

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

the class MappingEntryBuilderTest method testMapRecordConversion.

private void testMapRecordConversion(LispMapRecord record) {
    MappingEntry mappingEntry = new MappingEntryBuilder(DEVICE_ID, record).build();
    MappingKey key = mappingEntry.key();
    MappingValue value = mappingEntry.value();
    IPMappingAddress recordAddress = (IPMappingAddress) key.address();
    assertThat(recordAddress.ip(), is(IpPrefix.valueOf(IP_RECORD_ADDRESS + "/" + IP_RECORD_MASK_LENGTH)));
    assertThat(value.action().type(), is(MappingAction.Type.NATIVE_FORWARD));
    assertThat(value.treatments().size(), is(1));
    MappingTreatment treatment = value.treatments().get(0);
    IPMappingAddress locatorAddress = (IPMappingAddress) treatment.address();
    assertThat(locatorAddress.ip(), is(IpPrefix.valueOf(IPV4_ADDRESS_1 + "/" + IP_LOCATOR_MASK_LENGTH)));
}
Also used : MappingEntry(org.onosproject.mapping.MappingEntry) IPMappingAddress(org.onosproject.mapping.addresses.IPMappingAddress) MappingKey(org.onosproject.mapping.MappingKey) MappingValue(org.onosproject.mapping.MappingValue) MappingTreatment(org.onosproject.mapping.MappingTreatment)

Example 4 with MappingEntry

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

the class MappingEntryBuilderTest method getMappingAddressByAfiType.

private MappingAddress getMappingAddressByAfiType(AddressFamilyIdentifierEnum afiType, LispCanonicalAddressFormatEnum lcafType) {
    LispMapRecord record = getMapRecord(afiType, lcafType);
    MappingEntry entry = new MappingEntryBuilder(DEVICE_ID, record).build();
    return entry.value().treatments().get(0).address();
}
Also used : MappingEntry(org.onosproject.mapping.MappingEntry) LispMapRecord(org.onosproject.lisp.msg.protocols.LispMapRecord)

Example 5 with MappingEntry

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

Aggregations

MappingEntry (org.onosproject.mapping.MappingEntry)9 DefaultMapping (org.onosproject.mapping.DefaultMapping)4 DefaultMappingEntry (org.onosproject.mapping.DefaultMappingEntry)4 Mapping (org.onosproject.mapping.Mapping)4 Test (org.junit.Test)3 MappingKey (org.onosproject.mapping.MappingKey)3 MappingTreatment (org.onosproject.mapping.MappingTreatment)3 MappingValue (org.onosproject.mapping.MappingValue)3 DefaultMappingKey (org.onosproject.mapping.DefaultMappingKey)2 DefaultMappingTreatment (org.onosproject.mapping.DefaultMappingTreatment)2 DefaultMappingValue (org.onosproject.mapping.DefaultMappingValue)2 MappingAction (org.onosproject.mapping.actions.MappingAction)2 MappingAddress (org.onosproject.mapping.addresses.MappingAddress)2 MappingInstruction (org.onosproject.mapping.instructions.MappingInstruction)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 ItemNotFoundException (org.onlab.util.ItemNotFoundException)1 LispMapRecord (org.onosproject.lisp.msg.protocols.LispMapRecord)1