use of org.onosproject.mapping.addresses.MappingAddress 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.addresses.MappingAddress 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();
}
use of org.onosproject.mapping.addresses.MappingAddress in project onos by opennetworkinglab.
the class MappingTreatmentCodec method decode.
@Override
public MappingTreatment decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
final JsonCodec<MappingInstruction> instructionCodec = context.codec(MappingInstruction.class);
JsonNode instructionJson = json.get(INSTRUCTIONS);
MappingTreatment.Builder builder = DefaultMappingTreatment.builder();
if (instructionJson != null) {
IntStream.range(0, instructionJson.size()).forEach(i -> builder.add(instructionCodec.decode(get(instructionJson, i), context)));
}
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();
}
use of org.onosproject.mapping.addresses.MappingAddress in project onos by opennetworkinglab.
the class MappingTreatmentCodec method encode.
@Override
public ObjectNode encode(MappingTreatment treatment, CodecContext context) {
checkNotNull(treatment, "Mapping treatment cannot be null");
final ObjectNode result = context.mapper().createObjectNode();
final ArrayNode jsonInstructions = result.putArray(INSTRUCTIONS);
final JsonCodec<MappingInstruction> instructionCodec = context.codec(MappingInstruction.class);
final JsonCodec<MappingAddress> addressCodec = context.codec(MappingAddress.class);
for (final MappingInstruction instruction : treatment.instructions()) {
jsonInstructions.add(instructionCodec.encode(instruction, context));
}
result.set(ADDRESS, addressCodec.encode(treatment.address(), context));
return result;
}
use of org.onosproject.mapping.addresses.MappingAddress in project onos by opennetworkinglab.
the class DefaultMappingTreatmentTest method testEquals.
/**
* Tests equals() method.
*/
@Test
public void testEquals() {
IpPrefix ip1 = IpPrefix.valueOf(IP_ADDRESS_1);
MappingAddress address1 = MappingAddresses.ipv4MappingAddress(ip1);
MappingTreatment treatment1 = DefaultMappingTreatment.builder().withAddress(address1).setUnicastPriority(10).setUnicastWeight(10).build();
MappingTreatment sameAsTreatment1 = DefaultMappingTreatment.builder().withAddress(address1).setUnicastPriority(10).setUnicastWeight(10).build();
IpPrefix ip2 = IpPrefix.valueOf(IP_ADDRESS_2);
MappingAddress address2 = MappingAddresses.ipv4MappingAddress(ip2);
MappingTreatment treatment2 = DefaultMappingTreatment.builder().withAddress(address2).setMulticastPriority(20).setMulticastWeight(20).build();
new EqualsTester().addEqualityGroup(treatment1, sameAsTreatment1).addEqualityGroup(treatment2).testEquals();
}
Aggregations