use of org.onosproject.mapping.MappingKey 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));
}
use of org.onosproject.mapping.MappingKey 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();
}
use of org.onosproject.mapping.MappingKey in project onos by opennetworkinglab.
the class MappingEntryCodec method encode.
@Override
public ObjectNode encode(MappingEntry mappingEntry, CodecContext context) {
checkNotNull(mappingEntry, "Mapping entry cannot be null");
final ObjectNode result = context.mapper().createObjectNode().put(ID, Long.toString(mappingEntry.id().value())).put(DEVICE_ID, mappingEntry.deviceId().toString()).put(STATE, mappingEntry.state().toString());
if (mappingEntry.key() != null) {
final JsonCodec<MappingKey> keyCodec = context.codec(MappingKey.class);
result.set(KEY, keyCodec.encode(mappingEntry.key(), context));
}
if (mappingEntry.value() != null) {
final JsonCodec<MappingValue> valueCodec = context.codec(MappingValue.class);
result.set(VALUE, valueCodec.encode(mappingEntry.value(), context));
}
return result;
}
use of org.onosproject.mapping.MappingKey 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();
}
Aggregations