blob: fd7863acc12d49e89054ced08111def1c5559b6d [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001/**
2* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
3* University
4*
5* Licensed under the Apache License, Version 2.0 (the "License"); you may
6* not use this file except in compliance with the License. You may obtain
7* a copy of the License at
8*
9* http://www.apache.org/licenses/LICENSE-2.0
10*
11* Unless required by applicable law or agreed to in writing, software
12* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14* License for the specific language governing permissions and limitations
15* under the License.
16**/
17
18package org.openflow.protocol;
19
20import junit.framework.TestCase;
21
22public class OFMatchTest extends TestCase {
23 public void testFromString() {
24 OFMatch correct = new OFMatch();
25 OFMatch tester = new OFMatch();
26
27 // Various combinations of "all"/"any"
28 tester.fromString("OFMatch[]");
29 // correct is already wildcarded
30 TestCase.assertEquals(correct, tester);
31 tester.fromString("all");
32 TestCase.assertEquals(correct, tester);
33 tester.fromString("ANY");
34 TestCase.assertEquals(correct, tester);
35 tester.fromString("");
36 TestCase.assertEquals(correct, tester);
37 tester.fromString("[]");
38 TestCase.assertEquals(correct, tester);
39
40 // ip_src
41 correct.setWildcards(~OFMatch.OFPFW_NW_SRC_MASK);
42 correct.setNetworkSource(0x01010203);
43 tester.fromString("nw_src=1.1.2.3");
44 TestCase.assertEquals(correct.getNetworkSourceMaskLen(), tester
45 .getNetworkSourceMaskLen());
46 TestCase.assertEquals(correct, tester);
47 tester.fromString("IP_sRc=1.1.2.3");
48 TestCase.assertEquals(correct.getNetworkSourceMaskLen(), tester
49 .getNetworkSourceMaskLen());
50 TestCase.assertEquals(correct, tester);
51
52 // 0xVlan
53 correct = new OFMatch();
54 correct.setDataLayerVirtualLan((short)65535);
55 correct.setWildcards(~OFMatch.OFPFW_DL_VLAN);
56 tester = new OFMatch();
57 tester.fromString("dl_vlan=0xffff");
58 TestCase.assertEquals(correct, tester);
59 }
60
61 public void testToString() {
62 OFMatch match = new OFMatch();
63 match.fromString("nw_dst=3.4.5.6/8");
64 TestCase.assertEquals(8, match.getNetworkDestinationMaskLen());
65 String correct = "OFMatch[nw_dst=3.0.0.0/8]";
66 String tester = match.toString();
67
68 TestCase.assertEquals(correct, tester);
69 tester = "OFMatch[dl_type=35020]";
70 correct = "OFMatch[dl_type=0x88cc]";
71 match = new OFMatch();
72 match.fromString(tester);
73 TestCase.assertEquals(correct, match.toString());
74 OFMatch match2 = new OFMatch();
75 match2.fromString(correct);
76 TestCase.assertEquals(match, match2);
77 }
78
79 public void testClone() {
80 OFMatch match1 = new OFMatch();
81 OFMatch match2 = match1.clone();
82 TestCase.assertEquals(match1, match2);
83 match2.setNetworkProtocol((byte) 4);
84 match2.setWildcards(match2.getWildcards() & ~OFMatch.OFPFW_NW_PROTO);
85 TestCase.assertNotSame(match1, match2);
86 }
87
88 public void testIpToString() {
89 String test = OFMatch.ipToString(-1);
90 TestCase.assertEquals("255.255.255.255", test);
91 }
92}