use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie 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.flow.types.rev131026.FlowCookie in project openflowplugin by opendaylight.
the class FlowRegistryKeyFactoryTest method testGetHash2.
@Test
public void testGetHash2() throws Exception {
MatchBuilder match1Builder = new MatchBuilder().setLayer3Match(new Ipv4MatchBuilder().setIpv4Destination(new Ipv4Prefix("10.0.1.157/32")).build());
FlowBuilder flow1Builder = new FlowBuilder().setCookie(new FlowCookie(BigInteger.valueOf(483))).setMatch(match1Builder.build()).setPriority(2).setTableId((short) 0);
FlowRegistryKey flow1Hash = FlowRegistryKeyFactory.create(deviceInfo.getVersion(), flow1Builder.build());
LOG.info("flowHash1: {}", flow1Hash.hashCode());
MatchBuilder match2Builder = new MatchBuilder().setLayer3Match(new Ipv4MatchBuilder().setIpv4Destination(new Ipv4Prefix("10.0.0.242/32")).build());
FlowBuilder flow2Builder = new FlowBuilder(flow1Builder.build()).setCookie(new FlowCookie(BigInteger.valueOf(148))).setMatch(match2Builder.build());
FlowRegistryKey flow2Hash = FlowRegistryKeyFactory.create(deviceInfo.getVersion(), flow2Builder.build());
LOG.info("flowHash2: {}", flow2Hash.hashCode());
Assert.assertNotSame(flow1Hash, flow2Hash);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie in project openflowplugin by opendaylight.
the class FlowCreatorUtilTest method testCanModifyFlow.
/**
* Test method for
* {@link FlowCreatorUtil#canModifyFlow(OriginalFlow, UpdatedFlow, Short)}.
*/
@Test
public void testCanModifyFlow() {
final Short of10 = Short.valueOf(OFConstants.OFP_VERSION_1_0);
final Short of13 = Short.valueOf(OFConstants.OFP_VERSION_1_3);
final Short[] versions = { null, of10, of13 };
final Boolean[] bools = { null, Boolean.TRUE, Boolean.FALSE };
final Integer defPri = Integer.valueOf(0x8000);
final Integer defIdle = Integer.valueOf(0);
final Integer defHard = Integer.valueOf(0);
final FlowModFlags defFlags = FlowModFlags.getDefaultInstance("sENDFLOWREM");
final FlowModFlags flags = new FlowModFlags(false, true, false, true, false);
final FlowCookie defCookie = new FlowCookie(BigInteger.ZERO);
final FlowCookie cookie = new FlowCookie(BigInteger.valueOf(0x12345L));
final FlowCookie cookie1 = new FlowCookie(BigInteger.valueOf(0x67890L));
final FlowCookie cookieMask = new FlowCookie(BigInteger.valueOf(0xffff00L));
for (final Short ver : versions) {
final OriginalFlowBuilder originalBuilder = new OriginalFlowBuilder();
final UpdatedFlowBuilder updatedBuilder = new UpdatedFlowBuilder();
canModifyFlowTest(true, originalBuilder, updatedBuilder, ver);
// Default value tests.
canModifyFlowTest(true, new OriginalFlowBuilder().setPriority(defPri), updatedBuilder, ver);
canModifyFlowTest(true, originalBuilder, new UpdatedFlowBuilder().setPriority(defPri), ver);
canModifyFlowTest(true, new OriginalFlowBuilder().setIdleTimeout(defIdle), updatedBuilder, ver);
canModifyFlowTest(true, originalBuilder, new UpdatedFlowBuilder().setIdleTimeout(defIdle), ver);
canModifyFlowTest(true, new OriginalFlowBuilder().setHardTimeout(defHard), updatedBuilder, ver);
canModifyFlowTest(true, originalBuilder, new UpdatedFlowBuilder().setHardTimeout(defHard), ver);
canModifyFlowTest(false, new OriginalFlowBuilder().setFlags(defFlags), updatedBuilder, ver);
canModifyFlowTest(false, originalBuilder, new UpdatedFlowBuilder().setFlags(defFlags), ver);
canModifyFlowTest(true, new OriginalFlowBuilder().setCookie(defCookie), updatedBuilder, ver);
canModifyFlowTest(true, originalBuilder, new UpdatedFlowBuilder().setCookie(defCookie), ver);
// Set non-default values.
canModifyFlowTest(true, originalBuilder.setMatch(createMatch(0x800L)), updatedBuilder.setMatch(createMatch(0x800L)), ver);
canModifyFlowTest(true, originalBuilder.setIdleTimeout(600), updatedBuilder.setIdleTimeout(600), ver);
canModifyFlowTest(true, originalBuilder.setHardTimeout(1200), updatedBuilder.setHardTimeout(1200), ver);
canModifyFlowTest(true, originalBuilder.setPriority(100), updatedBuilder.setPriority(100), ver);
canModifyFlowTest(true, originalBuilder.setFlags(flags), updatedBuilder.setFlags(flags), ver);
canModifyFlowTest(true, originalBuilder.setCookie(cookie), updatedBuilder.setCookie(cookie), ver);
final OriginalFlow org = originalBuilder.build();
final UpdatedFlow upd = updatedBuilder.build();
// Set different match.
final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match[] matches = { null, createMatch(0x86ddL) };
for (final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match m : matches) {
canModifyFlowTest(false, originalBuilder, new UpdatedFlowBuilder(upd).setMatch(m), ver);
canModifyFlowTest(false, new OriginalFlowBuilder(org).setMatch(m), updatedBuilder, ver);
}
// Set different idle-timeout, hard-timeout, priority.
final Integer[] integers = { null, Integer.valueOf(3600) };
for (final Integer i : integers) {
canModifyFlowTest(false, originalBuilder, new UpdatedFlowBuilder(upd).setIdleTimeout(i), ver);
canModifyFlowTest(false, new OriginalFlowBuilder(org).setIdleTimeout(i), updatedBuilder, ver);
canModifyFlowTest(false, originalBuilder, new UpdatedFlowBuilder(upd).setHardTimeout(i), ver);
canModifyFlowTest(false, new OriginalFlowBuilder(org).setHardTimeout(i), updatedBuilder, ver);
canModifyFlowTest(false, originalBuilder, new UpdatedFlowBuilder(upd).setPriority(i), ver);
canModifyFlowTest(false, new OriginalFlowBuilder(org).setPriority(i), updatedBuilder, ver);
}
// Set different FLOW_MOD flags.
final FlowModFlags[] flowModFlags = { null, defFlags, new FlowModFlags(true, true, true, true, true) };
for (final FlowModFlags f : flowModFlags) {
canModifyFlowTest(false, originalBuilder, new UpdatedFlowBuilder(upd).setFlags(f), ver);
canModifyFlowTest(false, new OriginalFlowBuilder(org).setFlags(f), updatedBuilder, ver);
}
// Set different cookie.
final FlowCookie[] cookies = { null, defCookie, new FlowCookie(BigInteger.valueOf(0x123456L)) };
for (final FlowCookie c : cookies) {
canModifyFlowTest(false, originalBuilder, new UpdatedFlowBuilder(upd).setCookie(c), ver);
canModifyFlowTest(false, new OriginalFlowBuilder(org).setCookie(c), updatedBuilder, ver);
}
// Cookie mask test.
// Cookie mask is used by OF13 non-strict MODIFY command.
updatedBuilder.setCookie(cookie1);
for (final Boolean strict : bools) {
updatedBuilder.setCookieMask(null).setStrict(strict);
canModifyFlowTest(false, originalBuilder, updatedBuilder, ver);
updatedBuilder.setCookieMask(defCookie);
canModifyFlowTest(false, originalBuilder, updatedBuilder, ver);
updatedBuilder.setCookieMask(cookieMask);
final boolean expected = (of13.equals(ver) && !Boolean.TRUE.equals(strict));
canModifyFlowTest(expected, originalBuilder, updatedBuilder, ver);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie in project netvirt by opendaylight.
the class OpenFlow13Utils method createFlowBuilder.
public static FlowBuilder createFlowBuilder(final short table, final int priority, final BigInteger cookieValue, final String flowName, final String flowIdStr, MatchBuilder match, InstructionsBuilder isb) {
FlowBuilder flow = new FlowBuilder();
flow.setId(new FlowId(flowIdStr));
flow.setKey(new FlowKey(new FlowId(flowIdStr)));
flow.setTableId(table);
flow.setFlowName(flowName);
flow.setCookie(new FlowCookie(cookieValue));
flow.setCookieMask(new FlowCookie(cookieValue));
flow.setContainerName(null);
flow.setStrict(false);
flow.setMatch(match.build());
flow.setInstructions(isb.build());
flow.setPriority(priority);
flow.setHardTimeout(0);
flow.setIdleTimeout(0);
flow.setFlags(new FlowModFlags(false, false, false, false, false));
if (null == flow.isBarrier()) {
flow.setBarrier(Boolean.FALSE);
}
return flow;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie in project netvirt by opendaylight.
the class CountersServiceUtils method createFlowOnTable.
public static Flow createFlowOnTable(Match match, int priority, short tableId, BigInteger cookie, Integer timeout) {
FlowBuilder fb = new FlowBuilder();
if (match != null) {
fb.setMatch(match);
}
FlowId flowId = createFlowId();
fb.setTableId(tableId);
fb.setIdleTimeout(0).setHardTimeout(0);
fb.setId(flowId);
if (timeout != null) {
fb.setHardTimeout(timeout);
}
if (cookie != null) {
fb.setCookie(new FlowCookie(cookie));
}
fb.setPriority(priority);
Flow flow = fb.build();
return flow;
}
Aggregations