use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags in project openflowplugin by opendaylight.
the class MultipartReplyFlowTest method testMultipartReplyFlowBody.
/**
* Testing {@link MultipartReplyMessageFactory} for correct translation into POJO.
*/
@Test
public void testMultipartReplyFlowBody() {
ByteBuf bb = BufferHelper.buildBuffer(//
"00 01 00 01 00 00 00 00 " + // first flow stat
"00 48 08 00 " + // length, tableId, padding
"00 00 00 09 " + // durationSec
"00 00 00 07 " + // durationNsec
"00 0C 00 0E 00 0F 00 1F " + // priority, idleTimeout, hardTimeout, flags
"00 00 00 00 " + // pad_02
"FF 01 01 01 01 01 01 01 " + // cookie
"EF 01 01 01 01 01 01 01 " + // packetCount
"7F 01 01 01 01 01 01 01 " + // byteCount
"00 01 00 04 00 00 00 00 " + // empty match
"00 01 00 08 06 00 00 00 " + //
"00 01 00 08 06 00 00 00 " + // second flow stat
"00 48 08 00 " + // length, tableId, padding
"00 00 00 09 " + // durationSec
"00 00 00 07 " + // durationNsec
"00 0C 00 0E 00 0F 00 00 " + // priority, idleTimeout, hardTimeout, flags
"00 00 00 00 " + // pad_02
"FF 01 01 01 01 01 01 01 " + // cookie
"EF 01 01 01 01 01 01 01 " + // packetCount
"7F 01 01 01 01 01 01 01 " + // byteCount
"00 01 00 04 00 00 00 00 " + // empty match
"00 01 00 08 06 00 00 00 " + //
"00 01 00 08 06 00 00 00");
MultipartReplyMessage builtByFactory = BufferHelper.deserialize(factory, bb);
BufferHelper.checkHeaderV13(builtByFactory);
Assert.assertEquals("Wrong type", 0x01, builtByFactory.getType().getIntValue());
Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
MultipartReplyFlowCase messageCase = (MultipartReplyFlowCase) builtByFactory.getMultipartReplyBody();
MultipartReplyFlow message = messageCase.getMultipartReplyFlow();
Assert.assertEquals("Wrong flow stats size", 2, message.getFlowStats().size());
FlowStats flowStats1 = message.getFlowStats().get(0);
Assert.assertEquals("Wrong tableId", 8, flowStats1.getTableId().intValue());
Assert.assertEquals("Wrong durationSec", 9, flowStats1.getDurationSec().intValue());
Assert.assertEquals("Wrong durationNsec", 7, flowStats1.getDurationNsec().intValue());
Assert.assertEquals("Wrong priority", 12, flowStats1.getPriority().intValue());
Assert.assertEquals("Wrong idleTimeOut", 14, flowStats1.getIdleTimeout().intValue());
Assert.assertEquals("Wrong hardTimeOut", 15, flowStats1.getHardTimeout().intValue());
Assert.assertEquals("Wrong flags", new FlowModFlags(true, true, true, true, true), flowStats1.getFlags());
Assert.assertEquals("Wrong cookie", new BigInteger(1, new byte[] { (byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }), flowStats1.getCookie());
Assert.assertEquals("Wrong packetCount", new BigInteger(1, new byte[] { (byte) 0xEF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }), flowStats1.getPacketCount());
Assert.assertEquals("Wrong byteCount", new BigInteger(1, new byte[] { (byte) 0x7F, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }), flowStats1.getByteCount());
Assert.assertEquals("Wrong match type", OxmMatchType.class, flowStats1.getMatch().getType());
flowStats1 = message.getFlowStats().get(1);
Assert.assertEquals("Wrong tableId", 8, flowStats1.getTableId().intValue());
Assert.assertEquals("Wrong durationSec", 9, flowStats1.getDurationSec().intValue());
Assert.assertEquals("Wrong durationNsec", 7, flowStats1.getDurationNsec().intValue());
Assert.assertEquals("Wrong priority", 12, flowStats1.getPriority().intValue());
Assert.assertEquals("Wrong idleTimeOut", 14, flowStats1.getIdleTimeout().intValue());
Assert.assertEquals("Wrong hardTimeOut", 15, flowStats1.getHardTimeout().intValue());
Assert.assertEquals("Wrong flags", new FlowModFlags(false, false, false, false, false), flowStats1.getFlags());
Assert.assertEquals("Wrong cookie", new BigInteger(1, new byte[] { (byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }), flowStats1.getCookie());
Assert.assertEquals("Wrong packetCount", new BigInteger(1, new byte[] { (byte) 0xEF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }), flowStats1.getPacketCount());
Assert.assertEquals("Wrong byteCount", new BigInteger(1, new byte[] { (byte) 0x7F, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }), flowStats1.getByteCount());
Assert.assertEquals("Wrong match type", OxmMatchType.class, flowStats1.getMatch().getType());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags in project openflowplugin by opendaylight.
the class StatisticsGatheringUtilsTest method testGatherStatistics_flow.
@Test
public void testGatherStatistics_flow() throws Exception {
final short tableId = 0;
final MultipartType type = MultipartType.OFPMPFLOW;
final InstanceIdentifier<FlowCapableNode> nodePath = deviceInfo.getNodeInstanceIdentifier().augmentation(FlowCapableNode.class);
final TableBuilder tableDataBld = new TableBuilder();
tableDataBld.setId(tableId);
final FlowCapableNodeBuilder flowNodeBuilder = new FlowCapableNodeBuilder();
flowNodeBuilder.setTable(Collections.singletonList(tableDataBld.build()));
final Optional<FlowCapableNode> flowNodeOpt = Optional.of(flowNodeBuilder.build());
final CheckedFuture<Optional<FlowCapableNode>, ReadFailedException> flowNodeFuture = Futures.immediateCheckedFuture(flowNodeOpt);
when(readTx.read(LogicalDatastoreType.OPERATIONAL, nodePath)).thenReturn(flowNodeFuture);
when(flowDescriptor.getFlowId()).thenReturn(flowId);
final org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.MatchBuilder matchBld = new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.MatchBuilder().setMatchEntry(Collections.<MatchEntry>emptyList());
final FlowStatsBuilder flowStatsBld = new FlowStatsBuilder().setByteCount(BigInteger.valueOf(55L)).setPacketCount(BigInteger.valueOf(56L)).setDurationSec(57L).setDurationNsec(58L).setTableId((short) 0).setMatch(matchBld.build()).setFlags(new FlowModFlags(true, false, false, false, true));
final MultipartReplyFlowBuilder mpReplyFlowBld = new MultipartReplyFlowBuilder();
mpReplyFlowBld.setFlowStats(Lists.newArrayList(flowStatsBld.build()));
final MultipartReplyFlowCaseBuilder mpReplyFlowCaseBld = new MultipartReplyFlowCaseBuilder();
mpReplyFlowCaseBld.setMultipartReplyFlow(mpReplyFlowBld.build());
final MultipartReply flowStatsUpdated = assembleMPReplyMessage(type, mpReplyFlowCaseBld.build());
final List<MultipartReply> statsData = Collections.singletonList(flowStatsUpdated);
fireAndCheck(type, statsData);
final FlowBuilder flowBld = new FlowBuilder().setTableId((short) 0).setMatch(new MatchBuilder().build());
final KeyedInstanceIdentifier<Table, TableKey> tablePath = dummyNodePath.augmentation(FlowCapableNode.class).child(Table.class, new TableKey((short) 0));
final KeyedInstanceIdentifier<Flow, FlowKey> flowPath = tablePath.child(Flow.class, new FlowKey(flowId));
verify(deviceContext, Mockito.never()).addDeleteToTxChain(Matchers.eq(LogicalDatastoreType.OPERATIONAL), Matchers.<InstanceIdentifier<?>>any());
final InOrder inOrder = Mockito.inOrder(deviceContext);
inOrder.verify(deviceContext).writeToTransaction(Matchers.eq(LogicalDatastoreType.OPERATIONAL), Matchers.any(), Matchers.any());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags in project openflowplugin by opendaylight.
the class OFPluginFlowTest method createTestFlow.
static FlowBuilder createTestFlow() {
short tableId = 0;
FlowBuilder flow = new FlowBuilder();
flow.setMatch(createMatch1().build());
flow.setInstructions(createDecNwTtlInstructions().build());
FlowId flowId = new FlowId("127");
FlowKey key = new FlowKey(flowId);
if (null == flow.isBarrier()) {
flow.setBarrier(Boolean.FALSE);
}
BigInteger value = BigInteger.TEN;
flow.setCookie(new FlowCookie(value));
flow.setCookieMask(new FlowCookie(value));
flow.setHardTimeout(0);
flow.setIdleTimeout(0);
flow.setInstallHw(false);
flow.setStrict(false);
flow.setContainerName(null);
flow.setFlags(new FlowModFlags(false, false, false, false, true));
flow.setId(flowId);
flow.setTableId(tableId);
flow.setKey(key);
flow.setFlowName("Foo" + "X" + "f1");
return flow;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags in project openflowplugin by opendaylight.
the class FlowCreatorUtilTest method testEqualsFlowModFlags.
/**
* Test method for
* {@link FlowCreatorUtil#equalsFlowModFlags(FlowModFlags, FlowModFlags)}.
*/
@Test
public void testEqualsFlowModFlags() {
final FlowModFlags[] defaults = { null, new FlowModFlags(false, false, false, false, false), new FlowModFlags(false, null, false, null, Boolean.FALSE) };
final FlowModFlags all = new FlowModFlags(true, true, true, true, true);
final FlowModFlags none = new FlowModFlags(null, null, null, null, null);
for (final FlowModFlags f : defaults) {
assertTrue(FlowCreatorUtil.equalsFlowModFlags(f, (FlowModFlags) null));
assertTrue(FlowCreatorUtil.equalsFlowModFlags((FlowModFlags) null, f));
assertFalse(FlowCreatorUtil.equalsFlowModFlags((FlowModFlags) null, all));
assertFalse(FlowCreatorUtil.equalsFlowModFlags(all, (FlowModFlags) null));
assertTrue(FlowCreatorUtil.equalsFlowModFlags((FlowModFlags) null, none));
assertTrue(FlowCreatorUtil.equalsFlowModFlags(none, (FlowModFlags) null));
}
final String[] bitNames = { "cHECKOVERLAP", "nOBYTCOUNTS", "nOPKTCOUNTS", "rESETCOUNTS", "sENDFLOWREM" };
int bit = 0;
for (final String name : bitNames) {
final FlowModFlags flags = FlowModFlags.getDefaultInstance(name);
assertFalse(FlowCreatorUtil.equalsFlowModFlags(flags, all));
assertFalse(FlowCreatorUtil.equalsFlowModFlags(all, flags));
assertFalse(FlowCreatorUtil.equalsFlowModFlags(flags, none));
assertFalse(FlowCreatorUtil.equalsFlowModFlags(none, flags));
for (final String nm : bitNames) {
final FlowModFlags f = FlowModFlags.getDefaultInstance(nm);
final boolean expected = nm.equals(name);
assertEquals(expected, FlowCreatorUtil.equalsFlowModFlags(flags, f));
assertEquals(expected, FlowCreatorUtil.equalsFlowModFlags(f, flags));
}
final boolean overlap = (bit == 0);
final boolean noByte = (bit == 1);
final boolean noPacket = (bit == 2);
final boolean reset = (bit == 3);
final boolean flowRem = (bit == 4);
FlowModFlags flowModFlags = new FlowModFlags(overlap, noByte, noPacket, reset, flowRem);
assertTrue(FlowCreatorUtil.equalsFlowModFlags(flags, flowModFlags));
assertTrue(FlowCreatorUtil.equalsFlowModFlags(flowModFlags, flags));
assertTrue(FlowCreatorUtil.equalsFlowModFlags(flowModFlags, new FlowModFlags(flowModFlags)));
flowModFlags = new FlowModFlags(!overlap, noByte, noPacket, reset, flowRem);
assertFalse(FlowCreatorUtil.equalsFlowModFlags(flags, flowModFlags));
flowModFlags = new FlowModFlags(overlap, !noByte, noPacket, reset, flowRem);
assertFalse(FlowCreatorUtil.equalsFlowModFlags(flags, flowModFlags));
flowModFlags = new FlowModFlags(overlap, noByte, !noPacket, reset, flowRem);
assertFalse(FlowCreatorUtil.equalsFlowModFlags(flags, flowModFlags));
flowModFlags = new FlowModFlags(overlap, noByte, noPacket, !reset, flowRem);
assertFalse(FlowCreatorUtil.equalsFlowModFlags(flags, flowModFlags));
flowModFlags = new FlowModFlags(overlap, noByte, noPacket, reset, !flowRem);
assertFalse(FlowCreatorUtil.equalsFlowModFlags(flags, flowModFlags));
bit++;
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags 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());
}
Aggregations