use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode in project openflowplugin by opendaylight.
the class StatisticsGatheringUtils method deleteAllKnownFlows.
public static void deleteAllKnownFlows(final TxFacade txFacade, final InstanceIdentifier<FlowCapableNode> instanceIdentifier, final DeviceFlowRegistry deviceFlowRegistry) {
if (!txFacade.isTransactionsEnabled()) {
return;
}
final CheckedFuture<Optional<FlowCapableNode>, ReadFailedException> future;
try (ReadOnlyTransaction readTx = txFacade.getReadTransaction()) {
future = readTx.read(LogicalDatastoreType.OPERATIONAL, instanceIdentifier);
}
try {
Futures.transform(Futures.catchingAsync(future, Throwable.class, throwable -> {
return Futures.immediateFailedFuture(throwable);
}, MoreExecutors.directExecutor()), (Function<Optional<FlowCapableNode>, Void>) flowCapNodeOpt -> {
if (flowCapNodeOpt != null && flowCapNodeOpt.isPresent()) {
for (final Table tableData : flowCapNodeOpt.get().getTable()) {
final Table table = new TableBuilder(tableData).setFlow(Collections.emptyList()).build();
final InstanceIdentifier<Table> iiToTable = instanceIdentifier.child(Table.class, tableData.getKey());
txFacade.writeToTransaction(LogicalDatastoreType.OPERATIONAL, iiToTable, table);
}
}
return null;
}, MoreExecutors.directExecutor()).get();
} catch (InterruptedException | ExecutionException ex) {
LOG.debug("Failed to delete {} flows, exception: {}", deviceFlowRegistry.size(), ex);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode in project openflowplugin by opendaylight.
the class OFPluginFlowTest method testFlowMod.
/**
* test basic integration with OFLib running the handshake
* @throws Exception
*/
@Test
public void testFlowMod() throws Exception {
LOG.debug("testFlowMod integration test");
TriggerTestListener brmListener = new TriggerTestListener();
final DataTreeIdentifier<FlowCapableNode> dataTreeIdentifier = new DataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, getWildcardPath());
dataBroker.registerDataTreeChangeListener(dataTreeIdentifier, brmListener);
switchSim = createSimpleClient();
switchSim.setSecuredClient(false);
Deque<ClientEvent> handshakeScenario = ScenarioFactory.createHandshakeScenarioVBM(ScenarioFactory.VERSION_BITMAP_13, (short) 0, ScenarioFactory.VERSION_BITMAP_10_13, false);
handshakeScenario.addFirst(new SleepEvent(6000L));
ScenarioFactory.appendPostHandshakeScenario(handshakeScenario, true);
WaitForMessageEvent flowModEvent = new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 0e 00 58 00 00 00 03 00 00 00 00 00 00 00 0a " + "00 00 00 00 00 00 00 0a 00 00 00 00 00 00 80 00 " + "ff ff ff ff ff ff ff ff ff ff ff ff 00 01 00 00 " + "00 01 00 16 80 00 0a 02 08 00 80 00 19 08 0a 00 " + "00 01 ff ff ff 00 00 00 00 04 00 10 00 00 00 00 " + "00 18 00 08 00 00 00 00"));
handshakeScenario.addFirst(flowModEvent);
ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
switchSim.setScenarioHandler(scenario);
scenarioPool.execute(switchSim);
LOG.info("finishing testFlowMod");
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode in project openflowplugin by opendaylight.
the class OFPluginFlowTest method writeFlow.
static void writeFlow(FlowBuilder flow, InstanceIdentifier<FlowCapableNode> flowNodeIdent) {
ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
final InstanceIdentifier<Flow> path1 = flowNodeIdent.child(Table.class, new TableKey(flow.getTableId())).child(Flow.class, flow.getKey());
modification.merge(LogicalDatastoreType.CONFIGURATION, path1, flow.build(), true);
CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
Futures.addCallback(commitFuture, new FutureCallback<Void>() {
@Override
public void onSuccess(Void aVoid) {
LOG.debug("Write of flow on device succeeded.");
}
@Override
public void onFailure(Throwable throwable) {
LOG.error("Write of flow on device failed.", throwable);
}
}, MoreExecutors.directExecutor());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode in project openflowplugin by opendaylight.
the class MultipartRequestOnTheFlyCallbackTest method testOnSuccessWithValidMultipart1.
/**
* Not the last reply.
*/
@Test
public void testOnSuccessWithValidMultipart1() throws Exception {
final MatchBuilder matchBuilder = new MatchBuilder().setMatchEntry(Collections.<MatchEntry>emptyList());
final FlowStatsBuilder flowStatsBuilder = new FlowStatsBuilder().setTableId(tableId).setPriority(2).setCookie(BigInteger.ZERO).setByteCount(BigInteger.TEN).setPacketCount(BigInteger.ONE).setDurationSec(11L).setDurationNsec(12L).setMatch(matchBuilder.build()).setFlags(new FlowModFlags(true, false, false, false, false));
final MultipartReplyFlowBuilder multipartReplyFlowBuilder = new MultipartReplyFlowBuilder().setFlowStats(Collections.singletonList(flowStatsBuilder.build()));
final MultipartReplyFlowCaseBuilder multipartReplyFlowCaseBuilder = new MultipartReplyFlowCaseBuilder().setMultipartReplyFlow(multipartReplyFlowBuilder.build());
final MultipartReplyMessageBuilder mpReplyMessage = new MultipartReplyMessageBuilder().setType(MultipartType.OFPMPFLOW).setFlags(new MultipartRequestFlags(true)).setMultipartReplyBody(multipartReplyFlowCaseBuilder.build()).setXid(21L);
final InstanceIdentifier<FlowCapableNode> nodePath = mockedDeviceInfo.getNodeInstanceIdentifier().augmentation(FlowCapableNode.class);
final FlowCapableNodeBuilder flowNodeBuilder = new FlowCapableNodeBuilder();
final TableBuilder tableDataBld = new TableBuilder();
tableDataBld.setId(tableId);
flowNodeBuilder.setTable(Collections.singletonList(tableDataBld.build()));
final Optional<FlowCapableNode> flowNodeOpt = Optional.of(flowNodeBuilder.build());
final CheckedFuture<Optional<FlowCapableNode>, ReadFailedException> flowNodeFuture = Futures.immediateCheckedFuture(flowNodeOpt);
when(mockedReadOnlyTx.read(LogicalDatastoreType.OPERATIONAL, nodePath)).thenReturn(flowNodeFuture);
when(mockedDeviceContext.getReadTransaction()).thenReturn(mockedReadOnlyTx);
multipartRequestOnTheFlyCallback.onSuccess(mpReplyMessage.build());
verify(mockedReadOnlyTx, times(0)).read(LogicalDatastoreType.OPERATIONAL, nodePath);
verify(mockedReadOnlyTx, times(0)).close();
verify(mockedDeviceContext, times(1)).writeToTransaction(eq(LogicalDatastoreType.OPERATIONAL), Matchers.any(), Matchers.any());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode in project openflowplugin by opendaylight.
the class MultipartRequestOnTheFlyCallbackTest method initialization.
@Before
public void initialization() {
when(mockedDeviceContext.getMessageSpy()).thenReturn(new MessageIntelligenceAgencyImpl());
when(mockedNodeId.toString()).thenReturn(DUMMY_NODE_ID);
when(mockedPrimaryConnection.getNodeId()).thenReturn(mockedNodeId);
when(mockedPrimaryConnection.getFeatures()).thenReturn(mockedFeaturesReply);
when(mockedFeaturesReply.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
when(mockedFeaturesReply.getDatapathId()).thenReturn(BigInteger.valueOf(123L));
when(mocketGetFeaturesOutput.getTables()).thenReturn(tableId);
when(mocketGetFeaturesOutput.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
when(mocketGetFeaturesOutput.getDatapathId()).thenReturn(BigInteger.valueOf(123L));
when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedPrimaryConnection);
when(mockedDeviceInfo.getNodeInstanceIdentifier()).thenReturn(NODE_PATH);
when(mockedDeviceInfo.getNodeId()).thenReturn(mockedNodeId);
when(mockedDeviceInfo.getDatapathId()).thenReturn(BigInteger.TEN);
when(mockedDeviceInfo.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
when(mockedDeviceContext.getDeviceInfo()).thenReturn(mockedDeviceInfo);
when(mockedDeviceContext.getDeviceFlowRegistry()).thenReturn(mockedFlowRegistry);
when(mockedFlowRegistry.retrieveDescriptor(Matchers.any(FlowRegistryKey.class))).thenReturn(mockedFlowDescriptor);
final InstanceIdentifier<FlowCapableNode> nodePath = mockedDeviceInfo.getNodeInstanceIdentifier().augmentation(FlowCapableNode.class);
final FlowCapableNodeBuilder flowNodeBuilder = new FlowCapableNodeBuilder();
flowNodeBuilder.setTable(Collections.<Table>emptyList());
final Optional<FlowCapableNode> flowNodeOpt = Optional.of(flowNodeBuilder.build());
final CheckedFuture<Optional<FlowCapableNode>, ReadFailedException> flowNodeFuture = Futures.immediateCheckedFuture(flowNodeOpt);
when(mockedReadOnlyTx.read(LogicalDatastoreType.OPERATIONAL, nodePath)).thenReturn(flowNodeFuture);
when(mockedDeviceContext.getReadTransaction()).thenReturn(mockedReadOnlyTx);
dummyRequestContext = new AbstractRequestContext<List<MultipartReply>>(DUMMY_XID) {
@Override
public void close() {
// NOOP
}
};
final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager();
multipartRequestOnTheFlyCallback = new MultiLayerFlowMultipartRequestOnTheFlyCallback<>(dummyRequestContext, String.class, mockedDeviceContext, dummyEventIdentifier, MultipartWriterProviderFactory.createDefaultProvider(mockedDeviceContext), convertorManager);
}
Aggregations