use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.order.tlv.Order in project openflowplugin by opendaylight.
the class DeviceFlowRegistryImplTest method testFill.
@Test
public void testFill() throws Exception {
final InstanceIdentifier<FlowCapableNode> path = nodeInstanceIdentifier.augmentation(FlowCapableNode.class);
final Flow flow = new FlowBuilder().setTableId((short) 1).setPriority(10).setCookie(new FlowCookie(BigInteger.TEN)).setId(new FlowId("HELLO")).build();
final Table table = new TableBuilder().setFlow(Collections.singletonList(flow)).build();
final FlowCapableNode flowCapableNode = new FlowCapableNodeBuilder().setTable(Collections.singletonList(table)).build();
final Map<FlowRegistryKey, FlowDescriptor> allFlowDescriptors = fillRegistry(path, flowCapableNode);
key = FlowRegistryKeyFactory.create(OFConstants.OFP_VERSION_1_3, flow);
InOrder order = inOrder(dataBroker, readOnlyTransaction);
order.verify(dataBroker).newReadOnlyTransaction();
order.verify(readOnlyTransaction).read(LogicalDatastoreType.CONFIGURATION, path);
order.verify(dataBroker).newReadOnlyTransaction();
order.verify(readOnlyTransaction).read(LogicalDatastoreType.OPERATIONAL, path);
assertTrue(allFlowDescriptors.containsKey(key));
deviceFlowRegistry.addMark(key);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.order.tlv.Order in project openflowplugin by opendaylight.
the class WriteActionsInstructionSerializerTest method testSerialize.
@Test
public void testSerialize() throws Exception {
final int order = 0;
final Ipv4Prefix prefix = new Ipv4Prefix("192.168.76.0/32");
final Instruction instruction = new WriteActionsCaseBuilder().setWriteActions(new WriteActionsBuilder().setAction(Collections.singletonList(new ActionBuilder().setOrder(order).setKey(new ActionKey(order)).setAction(new SetNwSrcActionCaseBuilder().setSetNwSrcAction(new SetNwSrcActionBuilder().setAddress(new Ipv4Builder().setIpv4Address(prefix).build()).build()).build()).build())).build()).build();
assertInstruction(instruction, out -> {
out.skipBytes(InstructionConstants.PADDING_IN_ACTIONS_INSTRUCTION);
assertEquals(out.readUnsignedShort(), ActionConstants.SET_FIELD_CODE);
// Skip length of set field action
out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
assertEquals(out.readUnsignedShort(), OxmMatchConstants.OPENFLOW_BASIC_CLASS);
assertEquals(out.readUnsignedByte(), OxmMatchConstants.IPV4_SRC << 1);
// Skip match entry length
out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
byte[] addressBytes = new byte[4];
out.readBytes(addressBytes);
assertArrayEquals(addressBytes, new byte[] { (byte) 192, (byte) 168, 76, 0 });
// Padding at end
out.skipBytes(4);
});
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.order.tlv.Order in project lispflowmapping by opendaylight.
the class MappingMergeUtil method getCommonLocatorRecords.
private static List<LocatorRecord> getCommonLocatorRecords(MappingRecord nbMapping, MappingRecord sbMapping) {
// Return null when NB is a negative mapping
if (nbMapping.getLocatorRecord() == null || nbMapping.getLocatorRecord().isEmpty()) {
return null;
}
List<LocatorRecord> sbLocators = sbMapping.getLocatorRecord();
// We assume locators are unique and don't show up several times (with different or identical p/w/mp/mw),
// so we create a HashMap of the locators from the SB mapping record, keyed by the Rloc
Map<Rloc, LocatorRecord> sbLocatorMap = new HashMap<Rloc, LocatorRecord>();
for (LocatorRecord locator : sbLocators) {
sbLocatorMap.put(locator.getRloc(), locator);
}
// Gradually building final list of common locators, in order that they appear in NB Mapping
List<LocatorRecord> commonLocators = new ArrayList<LocatorRecord>();
for (LocatorRecord nbLocator : nbMapping.getLocatorRecord()) {
Rloc nbRloc = nbLocator.getRloc();
if (sbLocatorMap.containsKey(nbRloc)) {
if (sbLocatorMap.get(nbRloc).getPriority() == (short) 255) {
// if SB locator has p == 255 then common locator takes all NB fields except for p
// which must be set to 255
LocatorRecordBuilder lrb = new LocatorRecordBuilder(nbLocator);
lrb.setPriority((short) 255);
commonLocators.add(lrb.build());
} else {
commonLocators.add(nbLocator);
}
}
}
return commonLocators;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.order.tlv.Order in project lispflowmapping by opendaylight.
the class MappingMergeUtil method mergeLocatorRecords.
private static void mergeLocatorRecords(MappingRecordBuilder mrb, MappingRecord newRecord) {
List<LocatorRecord> locators = mrb.getLocatorRecord();
// We assume locators are unique and sorted and don't show up several times (with different or identical
// p/w/mp/mw), so we create a LinkedHashMap (which preserves order) of the locators from the existing merged
// record, keyed by the Rloc
Map<Rloc, LocatorRecord> locatorMap = new LinkedHashMap<Rloc, LocatorRecord>();
// All locators to be added to the merge set are first stored in this list
List<LocatorRecord> newLocatorList = new ArrayList<LocatorRecord>();
for (LocatorRecord locator : locators) {
locatorMap.put(locator.getRloc(), locator);
}
for (LocatorRecord newLocator : newRecord.getLocatorRecord()) {
Rloc newRloc = newLocator.getRloc();
if (locatorMap.containsKey(newRloc)) {
// overlapping locator
if (!locatorMap.get(newRloc).equals(newLocator)) {
LocatorRecord mergedLocator = mergeLocators(locatorMap.get(newRloc), newLocator);
newLocatorList.add(mergedLocator);
}
} else {
// new locator
newLocatorList.add(newLocator);
}
}
// Build new merged and sorted locator set if need be
if (!newLocatorList.isEmpty()) {
List<LocatorRecord> mergedLocators = new ArrayList<LocatorRecord>();
int mlocIt = 0;
int locIt = 0;
while (mlocIt < newLocatorList.size() && locIt < locators.size()) {
int cmp = compareLocators(locators.get(locIt), newLocatorList.get(mlocIt));
if (cmp < 0) {
mergedLocators.add(locators.get(locIt));
locIt++;
} else if (cmp > 0) {
mergedLocators.add(newLocatorList.get(mlocIt));
mlocIt++;
} else {
// when a locator appears in both lists, keep the new (merged) one and skip the old
mergedLocators.add(newLocatorList.get(mlocIt));
mlocIt++;
locIt++;
}
}
while (locIt < locators.size()) {
mergedLocators.add(locators.get(locIt));
locIt++;
}
while (mlocIt < newLocatorList.size()) {
mergedLocators.add(newLocatorList.get(mlocIt));
mlocIt++;
}
mrb.setLocatorRecord(mergedLocators);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.order.tlv.Order in project genius by opendaylight.
the class InterfaceManagerConfigurationTest method rebuildTerminationPoint.
private TerminationPoint rebuildTerminationPoint(TerminationPoint tp) {
// The problem we're fixing here is that, in MD-SAL binding v1, YANG lists are represented
// as Java lists but they don't preserve order (unless they specify “ordered-by user”).
// YANG keyed lists in particular are backed by maps, so you can store such a list in the
// MD-SAL and get it back in a different order.
// When comparing beans involving such lists, we need to sort the lists before comparing
// them. Retrieving the augmentation gives a modifiable list, so it's tempting to just
// sort that — but the list is re-created every time the augmentation is retrieved, so
// the sort is lost.
// To avoid all this, we rebuild instances of TerminationPoint, and sort the affected lists
// in the augmentations, with full augmentation rebuilds too (since the lists in a built
// augmentation might be unmodifiable).
TerminationPointBuilder newTpBuilder = new TerminationPointBuilder(tp);
OvsdbTerminationPointAugmentation ovsdbTpAugmentation = tp.getAugmentation(OvsdbTerminationPointAugmentation.class);
if (ovsdbTpAugmentation != null) {
OvsdbTerminationPointAugmentationBuilder newOvsdbTpAugmentationBuilder = new OvsdbTerminationPointAugmentationBuilder(ovsdbTpAugmentation);
if (ovsdbTpAugmentation.getOptions() != null) {
List<Options> options = new ArrayList<>(ovsdbTpAugmentation.getOptions());
options.sort(Comparator.comparing(o -> o.getKey().toString()));
newOvsdbTpAugmentationBuilder.setOptions(options);
}
if (ovsdbTpAugmentation.getInterfaceBfd() != null) {
List<InterfaceBfd> interfaceBfd = new ArrayList<>(ovsdbTpAugmentation.getInterfaceBfd());
interfaceBfd.sort(Comparator.comparing(o -> o.getKey().toString()));
newOvsdbTpAugmentationBuilder.setInterfaceBfd(interfaceBfd);
}
newTpBuilder.addAugmentation(OvsdbTerminationPointAugmentation.class, newOvsdbTpAugmentationBuilder.build());
}
return newTpBuilder.build();
}
Aggregations