use of org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowDescriptor in project openflowplugin by opendaylight.
the class DeviceContextImplTest method testProcessFlowRemovedMessage.
@Test
public void testProcessFlowRemovedMessage() throws Exception {
// prepare translation result
final FlowRemovedBuilder flowRemovedMdsalBld = new FlowRemovedBuilder().setTableId((short) 0).setPriority(42).setCookie(new FlowCookie(BigInteger.ONE)).setMatch(new MatchBuilder().build());
final NotificationPublishService mockedNotificationPublishService = mock(NotificationPublishService.class);
Mockito.when(messageTranslatorFlowRemoved.translate(any(Object.class), any(DeviceInfo.class), any(Object.class))).thenReturn(flowRemovedMdsalBld.build());
// insert flow+flowId into local registry
final FlowRegistryKey flowRegKey = FlowRegistryKeyFactory.create(deviceInfo.getVersion(), flowRemovedMdsalBld.build());
final FlowDescriptor flowDescriptor = FlowDescriptorFactory.create((short) 0, new FlowId("ut-ofp:f456"));
deviceContext.getDeviceFlowRegistry().storeDescriptor(flowRegKey, flowDescriptor);
// prepare empty input message
final FlowRemovedMessageBuilder flowRemovedBld = new FlowRemovedMessageBuilder();
// prepare path to flow to be removed
final KeyedInstanceIdentifier<Flow, FlowKey> flowToBeRemovedPath = nodeKeyIdent.augmentation(FlowCapableNode.class).child(Table.class, new TableKey((short) 0)).child(Flow.class, new FlowKey(new FlowId("ut-ofp:f456")));
deviceContext.setNotificationPublishService(mockedNotificationPublishService);
deviceContext.processFlowRemovedMessage(flowRemovedBld.build());
}
use of org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowDescriptor in project openflowplugin by opendaylight.
the class DeviceFlowRegistryImplTest method testStore.
@Test
public void testStore() throws Exception {
// store the same key with different value
final FlowDescriptor descriptor2 = FlowDescriptorFactory.create(key.getTableId(), new FlowId("ut:2"));
deviceFlowRegistry.storeDescriptor(key, descriptor2);
Assert.assertEquals(1, deviceFlowRegistry.getAllFlowDescriptors().size());
Assert.assertEquals("ut:2", deviceFlowRegistry.retrieveDescriptor(key).getFlowId().getValue());
// store new key with old value
final FlowAndStatisticsMapList flowStats = TestFlowHelper.createFlowAndStatisticsMapListBuilder(2).build();
final FlowRegistryKey key2 = FlowRegistryKeyFactory.create(OFConstants.OFP_VERSION_1_3, flowStats);
deviceFlowRegistry.storeDescriptor(key2, descriptor);
Assert.assertEquals(2, deviceFlowRegistry.getAllFlowDescriptors().size());
Assert.assertEquals("ut:1", deviceFlowRegistry.retrieveDescriptor(key2).getFlowId().getValue());
}
use of org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowDescriptor 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.openflowplugin.api.openflow.registry.flow.FlowDescriptor in project openflowplugin by opendaylight.
the class FlowStatsMultipartWriter method storeStatistics.
@Override
public void storeStatistics(final FlowAndStatisticsMapList statistics, final boolean withParents) {
statistics.getFlowAndStatisticsMapList().forEach(stat -> {
final FlowBuilder flow = new FlowBuilder(stat).addAugmentation(FlowStatisticsData.class, new FlowStatisticsDataBuilder().setFlowStatistics(new FlowStatisticsBuilder(stat).build()).build());
final FlowRegistryKey flowRegistryKey = FlowRegistryKeyFactory.create(version, flow.build());
registry.getDeviceFlowRegistry().store(flowRegistryKey);
final FlowDescriptor flowDescriptor = registry.getDeviceFlowRegistry().retrieveDescriptor(flowRegistryKey);
if (Objects.nonNull(flowDescriptor)) {
final FlowKey key = new FlowKey(flowDescriptor.getFlowId());
writeToTransaction(getInstanceIdentifier().augmentation(FlowCapableNode.class).child(Table.class, new TableKey(stat.getTableId())).child(Flow.class, key), flow.setId(key.getId()).setKey(key).build(), withParents);
}
});
}
use of org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowDescriptor in project openflowplugin by opendaylight.
the class SalFlowServiceImplTest method mockingFlowRegistryLookup.
private void mockingFlowRegistryLookup() {
FlowDescriptor mockedFlowDescriptor = mock(FlowDescriptor.class);
FlowId flowId = new FlowId(DUMMY_FLOW_ID);
when(mockedFlowDescriptor.getFlowId()).thenReturn(flowId);
when(mockedFlowDescriptor.getTableKey()).thenReturn(new TableKey(DUMMY_TABLE_ID));
when(deviceFlowRegistry.retrieveDescriptor(Matchers.any(FlowRegistryKey.class))).thenReturn(mockedFlowDescriptor);
}
Aggregations