X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=third-party%2Fopenflowj%2Fsrc%2Ftest%2Fjava%2Forg%2Fopenflow%2Fprotocol%2FOFMatchTest.java;fp=third-party%2Fopenflowj%2Fsrc%2Ftest%2Fjava%2Forg%2Fopenflow%2Fprotocol%2FOFMatchTest.java;h=8465598a77f1aff08bbe9b2bbe42bd45000b6ddf;hb=42210c03b0a4c54706320ba9f55794c0abd4d201;hp=0000000000000000000000000000000000000000;hpb=7576b38152b393793b1c9ec3df0ff86685f95236;p=controller.git diff --git a/third-party/openflowj/src/test/java/org/openflow/protocol/OFMatchTest.java b/third-party/openflowj/src/test/java/org/openflow/protocol/OFMatchTest.java new file mode 100644 index 0000000000..8465598a77 --- /dev/null +++ b/third-party/openflowj/src/test/java/org/openflow/protocol/OFMatchTest.java @@ -0,0 +1,111 @@ + +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.openflow.protocol; + +import junit.framework.TestCase; + +public class OFMatchTest extends TestCase { + public void testFromString() { + OFMatch correct = new OFMatch(); + OFMatch tester = new OFMatch(); + + // Various combinations of "all"/"any" + tester.fromString("OFMatch[]"); + // correct is already wildcarded + TestCase.assertEquals(correct, tester); + tester.fromString("all"); + TestCase.assertEquals(correct, tester); + tester.fromString("ANY"); + TestCase.assertEquals(correct, tester); + tester.fromString(""); + TestCase.assertEquals(correct, tester); + tester.fromString("[]"); + TestCase.assertEquals(correct, tester); + + // ip_src + correct.setWildcards(~OFMatch.OFPFW_NW_SRC_MASK); + correct.setNetworkSource(0x01010203); + tester.fromString("nw_src=1.1.2.3"); + TestCase.assertEquals(correct.getNetworkSourceMaskLen(), tester + .getNetworkSourceMaskLen()); + TestCase.assertEquals(correct, tester); + tester.fromString("IP_sRc=1.1.2.3"); + TestCase.assertEquals(correct.getNetworkSourceMaskLen(), tester + .getNetworkSourceMaskLen()); + TestCase.assertEquals(correct, tester); + } + + public void testToString() { + OFMatch match = new OFMatch(); + match.fromString("nw_dst=3.4.5.6/8"); + TestCase.assertEquals(8, match.getNetworkDestinationMaskLen()); + String correct = "OFMatch[nw_dst=3.0.0.0/8]"; + String tester = match.toString(); + + TestCase.assertEquals(correct, tester); + tester = "OFMatch[dl_type=35020]"; + correct = "OFMatch[dl_type=0x88cc]"; + match = new OFMatch(); + match.fromString(tester); + TestCase.assertEquals(correct, match.toString()); + OFMatch match2 = new OFMatch(); + match2.fromString(correct); + TestCase.assertEquals(match, match2); + } + + public void testClone() { + OFMatch match1 = new OFMatch(); + OFMatch match2 = match1.clone(); + TestCase.assertEquals(match1, match2); + match2.setNetworkProtocol((byte) 4); + match2.setWildcards(match2.getWildcards() & ~OFMatch.OFPFW_NW_PROTO); + TestCase.assertNotSame(match1, match2); + } + + public void testIpToString() { + String test = OFMatch.ipToString(-1); + TestCase.assertEquals("255.255.255.255", test); + } + + public void testReverse() { + OFMatch match1 = new OFMatch(); + OFMatch match2 = match1.reverse((short)0, true); + TestCase.assertEquals(match1, match2); + + match1.fromString("dl_dst=00:11:22:33:44:55"); + match2 = match1.reverse((short)0, true); + OFMatch match3 = new OFMatch(); + match3.fromString("dl_src=00:11:22:33:44:55"); + TestCase.assertEquals(match2, match3); + + match1.fromString("nw_dst=192.168.0.0/24"); + match2 = match1.reverse((short)0, true); + match3.fromString("nw_src=192.168.0.0/24"); + TestCase.assertEquals(match2, match3); + + match1.fromString("in_port=1"); + match2 = match1.reverse((short)2, false); + match3.fromString("in_port=2"); + TestCase.assertEquals(match2, match3); + } + + public void testSubsumes() { + OFMatch match1 = new OFMatch(); + OFMatch match2 = new OFMatch(); + match2.fromString("dl_dst=00:11:22:33:44:55"); + TestCase.assertTrue(match1.subsumes(match2)); + TestCase.assertFalse(match2.subsumes(match1)); + + match1.fromString("nw_dst=192.168.0.0/16"); + match2.fromString("nw_dst=192.168.0.0/24"); + TestCase.assertTrue(match1.subsumes(match2)); + TestCase.assertFalse(match2.subsumes(match1)); + } +}