Search in sources :

Example 11 with FlowRegistryKey

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));
}
Also used : FlowAndStatisticsMapListBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapListBuilder) FlowRegistryKey(org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey) FlowAndStatisticsMapList(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder) Ipv4MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder) Test(org.junit.Test)

Example 12 with FlowRegistryKey

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());
}
Also used : Ipv4MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder) FlowCookie(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie) FlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder) FlowRegistryKey(org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder) Ipv4MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder) Ipv4Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix) Test(org.junit.Test)

Aggregations

FlowRegistryKey (org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey)12 Test (org.junit.Test)9 FlowBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder)5 FlowDescriptor (org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowDescriptor)4 FlowId (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId)4 FlowAndStatisticsMapList (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList)4 FlowCookie (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie)4 MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder)4 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)3 Ipv4MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder)3 Ipv4Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix)2 FlowCapableNode (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode)2 Table (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table)2 TableKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey)2 FlowKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey)2 FlowStatisticsDataBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowStatisticsDataBuilder)2 FlowsStatisticsUpdate (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowsStatisticsUpdate)2 FlowStatisticsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.statistics.FlowStatisticsBuilder)2 HashSet (java.util.HashSet)1 InOrder (org.mockito.InOrder)1