blob: bd42ac8a1c9308f037e0710bcde856065898ad16 [file] [log] [blame]
HIGUCHI Yutad8dc9c02013-08-04 06:16:30 +09001package net.onrc.onos.ofcontroller.util;
2
3import static org.junit.Assert.*;
4import net.onrc.onos.ofcontroller.core.internal.TestableGraphDBOperation.TestFlowEntry;
5import net.onrc.onos.ofcontroller.core.internal.TestableGraphDBOperation.TestFlowPath;
6
7import org.junit.Before;
8import org.junit.Test;
9
10public class FlowPathTest {
11
12 FlowPath flowPath;
13
14 @Before
15 public void setUp() throws Exception{
16 TestFlowPath iFlowPath = new TestFlowPath();
17 iFlowPath.setFlowIdForTest("0x1234");
18 iFlowPath.setInstallerIdForTest("installerId");
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -070019 iFlowPath.setFlowPathTypeForTest("FP_TYPE_SHORTEST_PATH");
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -070020 iFlowPath.setFlowPathUserStateForTest("FP_USER_ADD");
HIGUCHI Yutad8dc9c02013-08-04 06:16:30 +090021 iFlowPath.setFlowPathFlagsForTest(0L);
22 iFlowPath.setSrcSwForTest("CA:FE");
23 iFlowPath.setSrcPortForTest((short)1);
24 iFlowPath.setDstSwForTest("BA:BE");
25 iFlowPath.setDstPortForTest((short)2);
26
27 iFlowPath.setActionsForTest("[[type=ACTION_OUTPUT action=[port=10 maxLen=11]];[type=ACTION_OUTPUT action=[port=12 maxLen=13]];]");
28
29 TestFlowEntry iFlowEntry = new TestFlowEntry();
30 iFlowEntry.setEntryIdForTest("0x14");
31 iFlowEntry.setDpidForTest("BE:EF");
32 iFlowEntry.setActionsForTest("[[type=ACTION_OUTPUT action=[port=23 maxLen=24]];[type=ACTION_OUTPUT action=[port=25 maxLen=26]];]");
33 iFlowEntry.setUserStateForTest("FE_USER_MODIFY");
34 iFlowEntry.setSwitchStateForTest("FE_SWITCH_UPDATE_IN_PROGRESS");
35 iFlowPath.addFlowEntryForTest(iFlowEntry);
36
37 flowPath = new FlowPath(iFlowPath);
38 }
39
40 @Test
41 public void testFlowPath(){
42 FlowPath flowPath = new FlowPath();
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -070043 assertTrue ( flowPath.flowPathType() == FlowPathType.FP_TYPE_UNKNOWN);
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -070044 assertTrue ( flowPath.flowPathUserState() == FlowPathUserState.FP_USER_UNKNOWN);
HIGUCHI Yutad8dc9c02013-08-04 06:16:30 +090045 assertFalse( flowPath.flowPathFlags().isDiscardFirstHopEntry() );
46 assertFalse( flowPath.flowPathFlags().isKeepOnlyFirstHopEntry() );
47 assertTrue( flowPath.flowEntryActions().isEmpty() );
48 }
49
50 @Test
51 public void testFlowPathIFlowPath(){
52 TestFlowPath iFlowPath = new TestFlowPath();
53 iFlowPath.setFlowIdForTest("0x1234");
54 iFlowPath.setInstallerIdForTest("installerId");
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -070055 iFlowPath.setFlowPathTypeForTest("FP_TYPE_SHORTEST_PATH");
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -070056 iFlowPath.setFlowPathUserStateForTest("FP_USER_ADD");
HIGUCHI Yutad8dc9c02013-08-04 06:16:30 +090057 iFlowPath.setFlowPathFlagsForTest(0L);
58 iFlowPath.setSrcSwForTest("CA:FE");
59 iFlowPath.setSrcPortForTest((short)1);
60 iFlowPath.setDstSwForTest("BA:BE");
61 iFlowPath.setDstPortForTest((short)2);
62
63 iFlowPath.setMatchSrcMacForTest("01:02:03:04:05:06");
64 iFlowPath.setMatchDstMacForTest("06:05:04:03:02:01");
65 iFlowPath.setMatchEthernetFrameTypeForTest((short)3);
66 iFlowPath.setMatchVlanIdForTest((short)4);
67 iFlowPath.setMatchVlanPriorityForTest((byte)5);
68 iFlowPath.setMatchSrcIpaddrForTest("127.0.0.1/32");
69 iFlowPath.setMatchDstIpaddrForTest("127.0.0.2/32");
70 iFlowPath.setMatchIpProtoForTest((byte)6);
71 iFlowPath.setMatchIpToSForTest((byte)7);
72 iFlowPath.setMatchSrcTcpUdpPortForTest((short)8);
73 iFlowPath.setMatchDstTcpUdpPortForTest((short)9);
74
75 iFlowPath.setActionsForTest("[[type=ACTION_OUTPUT action=[port=10 maxLen=11]];[type=ACTION_OUTPUT action=[port=12 maxLen=13]];]");
76
77 TestFlowEntry iFlowEntry = new TestFlowEntry();
78 iFlowEntry.setEntryIdForTest("0x14");
79 iFlowEntry.setDpidForTest("BE:EF");
80 iFlowEntry.setMatchInPortForTest((short)15);
81 iFlowEntry.setMatchSrcMacForTest("11:22:33:44:55:66");
82 iFlowEntry.setMatchDstMacForTest("66:55:44:33:22:11");
83 iFlowEntry.setMatchEtherFrameTypeForTest((short)16);
84 iFlowEntry.setMatchVlanIdForTest((short)17);
85 iFlowEntry.setMatchVlanPriorityForTest((byte)18);
86 iFlowEntry.setMatchSrcIpaddrForTest("127.0.0.3/32");
87 iFlowEntry.setMatchDstIpaddrForTest("127.0.0.4/32");
88 iFlowEntry.setMatchIpProtoForTest((byte)19);
89 iFlowEntry.setMatchIpToSForTest((byte)20);
90 iFlowEntry.setMatchSrcTcpUdpPortForTest((short)21);
91 iFlowEntry.setMatchDstTcpUdpPortForTest((short)22);
92 iFlowEntry.setActionsForTest("[[type=ACTION_OUTPUT action=[port=23 maxLen=24]];[type=ACTION_OUTPUT action=[port=25 maxLen=26]];]");
93 iFlowEntry.setUserStateForTest("FE_USER_MODIFY");
94 iFlowEntry.setSwitchStateForTest("FE_SWITCH_UPDATE_IN_PROGRESS");
95 iFlowPath.addFlowEntryForTest(iFlowEntry);
96
97 FlowPath flowPath = new FlowPath(iFlowPath);
98 assertEquals(flowPath.flowId().value(), 0x1234);
99 assertEquals(flowPath.installerId().value(), "installerId");
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -0700100 assertEquals(flowPath.flowPathType(), FlowPathType.FP_TYPE_SHORTEST_PATH);
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -0700101 assertEquals(flowPath.flowPathUserState(), FlowPathUserState.FP_USER_ADD);
HIGUCHI Yutad8dc9c02013-08-04 06:16:30 +0900102 assertEquals(flowPath.flowPathFlags().flags(), 0);
103 assertEquals(flowPath.dataPath().srcPort().dpid().value(), 0xCAFE);
104 assertEquals(flowPath.dataPath().srcPort().port().value(), 1);
105 assertEquals(flowPath.dataPath().dstPort().dpid().value(), 0xBABE);
106 assertEquals(flowPath.dataPath().dstPort().port().value(), 2);
107
108 assertEquals(flowPath.flowEntryMatch().srcMac().toString(), "01:02:03:04:05:06");
109 assertEquals(flowPath.flowEntryMatch().dstMac().toString(), "06:05:04:03:02:01");
110 assertEquals(flowPath.flowEntryMatch().ethernetFrameType().shortValue(), 3);
111 assertEquals(flowPath.flowEntryMatch().vlanId().shortValue(), 4);
112 assertEquals(flowPath.flowEntryMatch().vlanPriority().shortValue(), 5);
113 assertEquals(flowPath.flowEntryMatch().srcIPv4Net().address().toString(), "127.0.0.1");
114 assertEquals(flowPath.flowEntryMatch().srcIPv4Net().prefixLen() , 32);
115 assertEquals(flowPath.flowEntryMatch().dstIPv4Net().address().toString(), "127.0.0.2");
116 assertEquals(flowPath.flowEntryMatch().dstIPv4Net().prefixLen() , 32);
117 assertEquals(flowPath.flowEntryMatch().ipProto().byteValue(), 6);
118 assertEquals(flowPath.flowEntryMatch().ipToS().byteValue(), 7);
119 assertEquals(flowPath.flowEntryMatch().srcTcpUdpPort().shortValue(), 8);
120 assertEquals(flowPath.flowEntryMatch().dstTcpUdpPort().shortValue(), 9);
121
122 assertEquals(flowPath.flowEntryActions().toString(),"[[type=ACTION_OUTPUT action=[port=10 maxLen=11]];[type=ACTION_OUTPUT action=[port=12 maxLen=13]];]");
123
124 assertEquals(0x14, flowPath.dataPath().flowEntries().get(0).flowEntryId().value() );
125 assertEquals(0xBEEF, flowPath.dataPath().flowEntries().get(0).dpid().value() );
126 assertEquals(15, flowPath.dataPath().flowEntries().get(0).flowEntryMatch().inPort().value() );
127 assertEquals("11:22:33:44:55:66", flowPath.dataPath().flowEntries().get(0).flowEntryMatch().srcMac().toString());
128 assertEquals("66:55:44:33:22:11", flowPath.dataPath().flowEntries().get(0).flowEntryMatch().dstMac().toString());
129 assertEquals(16, flowPath.dataPath().flowEntries().get(0).flowEntryMatch().ethernetFrameType().shortValue());
130 assertEquals(17, flowPath.dataPath().flowEntries().get(0).flowEntryMatch().vlanId().shortValue());
131 assertEquals(18, flowPath.dataPath().flowEntries().get(0).flowEntryMatch().vlanPriority().byteValue());
132 assertEquals("127.0.0.3", flowPath.dataPath().flowEntries().get(0).flowEntryMatch().srcIPv4Net().address().toString());
133 assertEquals(32, flowPath.dataPath().flowEntries().get(0).flowEntryMatch().srcIPv4Net().prefixLen());
134 assertEquals("127.0.0.4", flowPath.dataPath().flowEntries().get(0).flowEntryMatch().dstIPv4Net().address().toString());
135 assertEquals(32, flowPath.dataPath().flowEntries().get(0).flowEntryMatch().dstIPv4Net().prefixLen());
136 assertEquals(19, flowPath.dataPath().flowEntries().get(0).flowEntryMatch().ipProto().byteValue());
137 assertEquals(20, flowPath.dataPath().flowEntries().get(0).flowEntryMatch().ipToS().byteValue());
138 assertEquals(21, flowPath.dataPath().flowEntries().get(0).flowEntryMatch().srcTcpUdpPort().shortValue());
139 assertEquals(22, flowPath.dataPath().flowEntries().get(0).flowEntryMatch().dstTcpUdpPort().shortValue());
140 assertEquals("[[type=ACTION_OUTPUT action=[port=23 maxLen=24]];[type=ACTION_OUTPUT action=[port=25 maxLen=26]];]", flowPath.dataPath().flowEntries().get(0).flowEntryActions().toString());
141 assertEquals("FE_USER_MODIFY", flowPath.dataPath().flowEntries().get(0).flowEntryUserState().toString());
142 assertEquals("FE_SWITCH_UPDATE_IN_PROGRESS", flowPath.dataPath().flowEntries().get(0).flowEntrySwitchState().toString());
143 }
144
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -0700145 @Test
146 public void testSetFlowPathType(){
147 FlowPath flowPath = new FlowPath();
148 FlowPathType type = FlowPathType.FP_TYPE_SHORTEST_PATH;
149 flowPath.setFlowPathType( type );
150 assertTrue( flowPath.flowPathType() == FlowPathType.FP_TYPE_SHORTEST_PATH );
151 }
HIGUCHI Yutad8dc9c02013-08-04 06:16:30 +0900152
153 @Test
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -0700154 public void testSetFlowPathUserState(){
155 FlowPath flowPath = new FlowPath();
156 FlowPathUserState state = FlowPathUserState.FP_USER_ADD;
157 flowPath.setFlowPathUserState( state );
158 assertTrue( flowPath.flowPathUserState() == FlowPathUserState.FP_USER_ADD );
159 }
160
161 @Test
HIGUCHI Yutad8dc9c02013-08-04 06:16:30 +0900162 public void testFlowPathFlags(){
163 FlowPath flowPath = new FlowPath();
164 FlowPathFlags flags = new FlowPathFlags();
165 flags.setFlags(0);
166 flowPath.setFlowPathFlags( flags );
167 assertFalse( flowPath.flowPathFlags().isDiscardFirstHopEntry() );
168 assertFalse( flowPath.flowPathFlags().isKeepOnlyFirstHopEntry() );
169 }
170
171 @Test
172 public void testSetFlowPathFlags(){
173 FlowPath flowPath = new FlowPath();
174 FlowPathFlags flags = new FlowPathFlags("DISCARD_FIRST_HOP_ENTRY");
175 flags.setFlagsStr("KEEP_ONLY_FIRST_HOP_ENTRY");
176 flowPath.setFlowPathFlags( flags );
177 assertFalse( flowPath.flowPathFlags().isDiscardFirstHopEntry() );
178 assertTrue( flowPath.flowPathFlags().isKeepOnlyFirstHopEntry() );
179 }
180
181 @Test
182 public void testSetDataPath(){
183 FlowPath flowPath = new FlowPath();
184 DataPath dataPath = new DataPath();
185 flowPath.setDataPath( dataPath );
186 assertEquals(flowPath.dataPath(), dataPath );
187 }
188
189 @Test
190 public void testToString(){
191
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -0700192 assertEquals("[flowId=0x1234 installerId=installerId flowPathType=FP_TYPE_SHORTEST_PATH flowPathUserState=FP_USER_ADD flowPathFlags=[flags=] dataPath=[src=00:00:00:00:00:00:ca:fe/1 flowEntry=[flowEntryId=0x14 flowEntryMatch=[] flowEntryActions=[[type=ACTION_OUTPUT action=[port=23 maxLen=24]];[type=ACTION_OUTPUT action=[port=25 maxLen=26]];] dpid=00:00:00:00:00:00:be:ef flowEntryUserState=FE_USER_MODIFY flowEntrySwitchState=FE_SWITCH_UPDATE_IN_PROGRESS] dst=00:00:00:00:00:00:ba:be/2] flowEntryMatch=[] flowEntryActions=[[type=ACTION_OUTPUT action=[port=10 maxLen=11]];[type=ACTION_OUTPUT action=[port=12 maxLen=13]];]]", flowPath.toString());
HIGUCHI Yutad8dc9c02013-08-04 06:16:30 +0900193 }
194
195 @Test
196 public void testCompareTo(){
197 FlowPath flowPath1 = new FlowPath();
198 flowPath1.setFlowId( new FlowId(1));
199 FlowPath flowPath2 = new FlowPath();
200 flowPath2.setFlowId( new FlowId(2));
201
202 assertTrue( flowPath1.compareTo(flowPath2) < 0);
203 }
204
205}