Search in sources :

Example 26 with MappingAddress

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

the class MappingKeyCodec method encode.

@Override
public ObjectNode encode(MappingKey key, CodecContext context) {
    checkNotNull(key, "Mapping key cannot be null");
    final ObjectNode result = context.mapper().createObjectNode();
    final JsonCodec<MappingAddress> addressCodec = context.codec(MappingAddress.class);
    result.set(ADDRESS, addressCodec.encode(key.address(), context));
    return result;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MappingAddress(org.onosproject.mapping.addresses.MappingAddress)

Example 27 with MappingAddress

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

the class DefaultMappingKeyTest method testEquals.

/**
 * Tests equals() method.
 */
@Test
public void testEquals() {
    IpPrefix ip1 = IpPrefix.valueOf(IP_ADDRESS_1);
    MappingAddress address1 = MappingAddresses.ipv4MappingAddress(ip1);
    MappingKey key1 = DefaultMappingKey.builder().withAddress(address1).build();
    MappingKey sameAsKey1 = DefaultMappingKey.builder().withAddress(address1).build();
    IpPrefix ip2 = IpPrefix.valueOf(IP_ADDRESS_2);
    MappingAddress address2 = MappingAddresses.ipv4MappingAddress(ip2);
    MappingKey key2 = DefaultMappingKey.builder().withAddress(address2).build();
    new EqualsTester().addEqualityGroup(key1, sameAsKey1).addEqualityGroup(key2).testEquals();
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) MappingAddress(org.onosproject.mapping.addresses.MappingAddress) EqualsTester(com.google.common.testing.EqualsTester) Test(org.junit.Test)

Example 28 with MappingAddress

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

the class DefaultMappingTreatmentTest method testBuilderMethods.

/**
 * Tests method defined on the Builder.
 */
@Test
public void testBuilderMethods() {
    IpPrefix ip = IpPrefix.valueOf(IP_ADDRESS_1);
    MappingAddress address = MappingAddresses.ipv4MappingAddress(ip);
    MappingTreatment.Builder builder = DefaultMappingTreatment.builder().withAddress(address).setUnicastPriority(10).setUnicastWeight(10);
    MappingTreatment treatment = builder.build();
    assertThat(treatment.instructions(), hasSize(2));
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) MappingAddress(org.onosproject.mapping.addresses.MappingAddress) Test(org.junit.Test)

Example 29 with MappingAddress

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

the class MappingTreatmentCodecTest method testMappingTreatmentEncode.

/**
 * Tests encoding of a mapping treatment object.
 */
@Test
public void testMappingTreatmentEncode() {
    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.asMappingAddress(ASN_NUMBER);
    MappingTreatment treatment = DefaultMappingTreatment.builder().add(unicastWeight).add(unicastPriority).add(multicastWeight).add(multicastPriority).withAddress(address).build();
    ObjectNode treatmentJson = treatmentCodec.encode(treatment, context);
    assertThat(treatmentJson, MappingTreatmentJsonMatcher.matchesMappingTreatment(treatment));
}
Also used : MappingAddress(org.onosproject.mapping.addresses.MappingAddress) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MappingTreatment(org.onosproject.mapping.MappingTreatment) DefaultMappingTreatment(org.onosproject.mapping.DefaultMappingTreatment) MappingInstruction(org.onosproject.mapping.instructions.MappingInstruction) Test(org.junit.Test)

Example 30 with MappingAddress

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

the class MappingAddressCodecTest method ipv6MappingAddressTest.

/**
 * Tests IPv6 mapping address.
 */
@Test
public void ipv6MappingAddressTest() {
    MappingAddress address = MappingAddresses.ipv6MappingAddress(IPV6_PREFIX);
    ObjectNode result = addressCodec.encode(address, context);
    assertThat(result, matchesMappingAddress(address));
}
Also used : MappingAddressJsonMatcher.matchesMappingAddress(org.onosproject.mapping.codec.MappingAddressJsonMatcher.matchesMappingAddress) MappingAddress(org.onosproject.mapping.addresses.MappingAddress) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) 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