use of org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey in project openflowplugin by opendaylight.
the class FlowRegistryKeyFactoryTest method testEqualsNegative.
@Test
public void testEqualsNegative() throws Exception {
final FlowAndStatisticsMapList flowStatisticsMapList1 = TestFlowHelper.createFlowAndStatisticsMapListBuilder(1).build();
final FlowRegistryKey key1 = FlowRegistryKeyFactory.create(deviceInfo.getVersion(), flowStatisticsMapList1);
FlowRegistryKey key2;
FlowAndStatisticsMapListBuilder flowStatisticsMapListBld2;
// different priority
flowStatisticsMapListBld2 = new FlowAndStatisticsMapListBuilder(flowStatisticsMapList1);
flowStatisticsMapListBld2.setPriority(flowStatisticsMapListBld2.getPriority() + 1);
key2 = FlowRegistryKeyFactory.create(deviceInfo.getVersion(), flowStatisticsMapListBld2.build());
Assert.assertFalse(key1.equals(key2));
// different match
flowStatisticsMapListBld2 = new FlowAndStatisticsMapListBuilder(flowStatisticsMapList1);
flowStatisticsMapListBld2.setMatch(new MatchBuilder().build());
key2 = FlowRegistryKeyFactory.create(deviceInfo.getVersion(), flowStatisticsMapListBld2.build());
Assert.assertFalse(key1.equals(key2));
// different tableId
flowStatisticsMapListBld2 = new FlowAndStatisticsMapListBuilder(flowStatisticsMapList1);
flowStatisticsMapListBld2.setTableId((short) (flowStatisticsMapListBld2.getTableId() + 1));
key2 = FlowRegistryKeyFactory.create(deviceInfo.getVersion(), flowStatisticsMapListBld2.build());
Assert.assertFalse(key1.equals(key2));
Assert.assertFalse(key1.equals(null));
}
use of org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey in project openflowplugin by opendaylight.
the class FlowRegistryKeyFactoryTest method testGetHashNPE.
@Test
public void testGetHashNPE() 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);
FlowBuilder fb1 = new FlowBuilder(flow1Builder.build());
fb1.setTableId(null);
try {
FlowRegistryKeyFactory.create(deviceInfo.getVersion(), fb1.build());
Assert.fail("hash creation should have failed because of NPE");
} catch (NullPointerException e) {
// expected
Assert.assertEquals("flow tableId must not be null", e.getMessage());
}
FlowBuilder fb2 = new FlowBuilder(flow1Builder.build());
fb2.setPriority(null);
try {
FlowRegistryKeyFactory.create(deviceInfo.getVersion(), fb2.build());
} catch (NullPointerException e) {
// not expected
Assert.fail("no exception was expected while hash was creating.");
}
FlowBuilder fb3 = new FlowBuilder(flow1Builder.build());
fb3.setCookie(null);
FlowRegistryKey flowRegistryKey = FlowRegistryKeyFactory.create(deviceInfo.getVersion(), fb3.build());
Assert.assertNotNull(flowRegistryKey.getCookie());
Assert.assertEquals(OFConstants.DEFAULT_COOKIE, flowRegistryKey.getCookie());
}
Aggregations