blob: 696f9e5f39c0d5aa017f4fbb6826fd0437594e54 [file] [log] [blame]
HIGUCHI Yutad8dc9c02013-08-04 06:16:30 +09001package net.onrc.onos.ofcontroller.util;
2
3import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.assertTrue;
5import net.floodlightcontroller.util.MACAddress;
6
7import org.junit.Before;
8import org.junit.Test;
9
10public class FlowEntryTest {
11
12 FlowEntry entry;
13
14 FlowId flowId = new FlowId(0x1234);
15 FlowEntryId flowEntryId = new FlowEntryId(0x5678);
Pavlin Radoslavov5139c0b2013-12-09 18:04:53 -080016 int idleTimeout = 5;
17 int hardTimeout = 10;
HIGUCHI Yutad8dc9c02013-08-04 06:16:30 +090018 FlowEntryMatch match;
19 FlowEntryActions actions;
20
21 Dpid dpid = new Dpid(0xCAFE);
22
23 Port inport = new Port((short)1);
24 byte[] byte1 = { 1, 2, 3, 4, 5, 6 };
25 byte[] byte2 = { 6, 5, 4, 3, 2, 1 };
26 MACAddress mac1 = new MACAddress(byte1);
27 MACAddress mac2 = new MACAddress(byte2);
28 Short ether = Short.valueOf((short)2);
29 Short vlanid = Short.valueOf((short)3);
30 Byte vlanprio = Byte.valueOf((byte)4);
31 IPv4Net ip1 = new IPv4Net("127.0.0.1/32");
32 IPv4Net ip2 = new IPv4Net( new IPv4("127.0.0.2"), (short)32);
33 IPv4 ipaddr1 = new IPv4("127.0.0.3");
34 IPv4 ipaddr2 = new IPv4("127.0.0.4");
35 Byte ipproto = Byte.valueOf((byte)5);
36 Byte ipToS = Byte.valueOf((byte)6);
37 Short tport1 = Short.valueOf((short)7);
38 Short tport2 = Short.valueOf((short)8);
39 Port outport = new Port((short)9);
40 Port queueport = new Port((short)10);
41 int queueId = 11;
42
43 FlowEntryErrorState errorState = new FlowEntryErrorState( (short)12, (short)13);
44
45
46 @Before
47 public void setUp() throws Exception{
48 entry = new FlowEntry();
49
50 flowId = new FlowId("0x1234");
51 entry.setFlowId( flowId );
52
53 flowEntryId = new FlowEntryId("0x5678");
54 entry.setFlowEntryId(flowEntryId);
Pavlin Radoslavov5139c0b2013-12-09 18:04:53 -080055
56 entry.setIdleTimeout(5);
57 entry.setHardTimeout(10);
HIGUCHI Yutad8dc9c02013-08-04 06:16:30 +090058
59 dpid = new Dpid("CA:FE");
60 entry.setDpid( dpid );
61
62 entry.setInPort( inport );
63 entry.setOutPort( outport );
64
65 match = new FlowEntryMatch();
66 match.enableInPort( inport);
67 match.enableSrcMac( mac1 );
68 match.enableDstMac( mac2 );
69 match.enableEthernetFrameType( ether );
70 match.enableVlanId( vlanid );
71 match.enableVlanPriority( vlanprio );
72 match.enableSrcIPv4Net( ip1 );
73 match.enableDstIPv4Net( ip2 );
74 match.enableIpProto( ipproto );
75 match.enableIpToS( ipToS );
76 match.enableSrcTcpUdpPort( tport1 );
77 match.enableDstTcpUdpPort( tport2 );
78
79 entry.setFlowEntryMatch( match );
80
81 FlowEntryAction action = null;
82 actions = entry.flowEntryActions();
83
84 action = new FlowEntryAction();
85 action.setActionOutput(outport);
86 actions.addAction(action);
87
88 action = new FlowEntryAction();
89 action.setActionOutputToController((short)0);
90 actions.addAction(action);
91
92 action = new FlowEntryAction();
93 action.setActionSetVlanId(vlanid);
94 actions.addAction(action);
95
96 action = new FlowEntryAction();
97 action.setActionSetVlanPriority(vlanprio);
98 actions.addAction(action);
99
100 action = new FlowEntryAction();
101 action.setActionStripVlan(true);
102 actions.addAction(action);
103
104 action = new FlowEntryAction();
105 action.setActionSetEthernetSrcAddr(mac1);
106 actions.addAction(action);
107
108 action = new FlowEntryAction();
109 action.setActionSetEthernetDstAddr(mac2);
110 actions.addAction(action);
111
112 action = new FlowEntryAction();
113 action.setActionSetIPv4SrcAddr(ipaddr1);
114 actions.addAction(action);
115
116 action = new FlowEntryAction();
117 action.setActionSetIPv4DstAddr(ipaddr2);
118 actions.addAction(action);
119
120 action = new FlowEntryAction();
121 action.setActionSetIpToS(ipToS);
122 actions.addAction(action);
123
124 action = new FlowEntryAction();
125 action.setActionSetTcpUdpSrcPort(tport1);
126 actions.addAction(action);
127
128 action = new FlowEntryAction();
129 action.setActionSetTcpUdpDstPort(tport2);
130 actions.addAction(action);
131
132 action = new FlowEntryAction();
133 action.setActionEnqueue(queueport, queueId);
134 actions.addAction(action);
135
136 entry.setFlowEntryUserState( FlowEntryUserState.FE_USER_ADD );
137 entry.setFlowEntrySwitchState( FlowEntrySwitchState.FE_SWITCH_UPDATED );
138 entry.setFlowEntryErrorState( errorState );
139
140 }
141
142 @Test
143 public void testFlowEntry(){
144 FlowEntry e = new FlowEntry();
145
146 assertTrue( e.flowEntryActions().isEmpty() );
147 assertEquals("flowEntryUserState", FlowEntryUserState.FE_USER_UNKNOWN, e.flowEntryUserState() );
148 assertEquals("flowEntrySwitchState", FlowEntrySwitchState.FE_SWITCH_UNKNOWN, e.flowEntrySwitchState() );
149 }
150
151 @Test
Pavlin Radoslavovb1309e82013-10-30 12:18:28 -0700152 public void testFlowId(){
153 assertEquals("flowId", flowId, entry.flowId() );
HIGUCHI Yutad8dc9c02013-08-04 06:16:30 +0900154 }
155
156 @Test
Pavlin Radoslavov062c72d2013-10-30 12:42:15 -0700157 public void testIsValidFlowId(){
158 FlowEntry e = new FlowEntry();
159
160 // Test a Flow Entry with empty Flow ID
161 assertEquals("isValidFlowId", false, e.isValidFlowId() );
162
163 // Test a Flow Entry with invalid Flow ID
164 e.setFlowId(new FlowId());
165 assertEquals("isValidFlowId", false, e.isValidFlowId() );
166
167 // Test a Flow Entry with valid Flow ID
168 e.setFlowId(new FlowId(0x1));
169 assertEquals("isValidFlowId", true, e.isValidFlowId() );
170 assertEquals("isValidFlowId", true, entry.isValidFlowId() );
171 }
172
173 @Test
HIGUCHI Yutad8dc9c02013-08-04 06:16:30 +0900174 public void testFlowEntryId(){
175 assertEquals("flowEntryId", flowEntryId, entry.flowEntryId() );
176 }
177
178 @Test
Pavlin Radoslavovb1309e82013-10-30 12:18:28 -0700179 public void testIsValidFlowEntryId(){
180 FlowEntry e = new FlowEntry();
181
182 // Test a Flow Entry with empty Flow Entry ID
183 assertEquals("isValidFlowEntryId", false, e.isValidFlowEntryId() );
184
185 // Test a Flow Entry with invalid Flow Entry ID
186 e.setFlowEntryId(new FlowEntryId());
187 assertEquals("isValidFlowEntryId", false, e.isValidFlowEntryId() );
188
189 // Test a Flow Entry with valid Flow Entry ID
190 e.setFlowEntryId(new FlowEntryId(0x1));
191 assertEquals("isValidFlowEntryId", true, e.isValidFlowEntryId() );
192 assertEquals("isValidFlowEntryId", true, entry.isValidFlowEntryId() );
193 }
194
195 @Test
Pavlin Radoslavov5139c0b2013-12-09 18:04:53 -0800196 public void testIdleTimeout(){
197 assertEquals("idleTimeout", idleTimeout, entry.idleTimeout() );
198 }
199
200 @Test
201 public void testHardTimeout(){
202 assertEquals("hardTimeout", hardTimeout, entry.hardTimeout() );
203 }
204
205 @Test
HIGUCHI Yutad8dc9c02013-08-04 06:16:30 +0900206 public void testFlowEntryMatch(){
207 assertEquals("flowEntryMatch", match, entry.flowEntryMatch() );
208 }
209
210 @Test
211 public void testFlowEntryActions(){
212 assertEquals("flowEntryActions", actions, entry.flowEntryActions() );
213 }
214
215 @Test
216 public void testSetFlowEntryActions(){
217 FlowEntryActions actions = new FlowEntryActions();
218 entry.setFlowEntryActions( actions );
219 assertEquals("flowEntryActions", actions, entry.flowEntryActions() );
220 }
221
222 @Test
223 public void testDpid(){
224 assertEquals("dpid", dpid, entry.dpid() );
225 }
226
227 @Test
228 public void testInPort(){
229 assertEquals("inPort", inport, entry.inPort() );
230 }
231
232 @Test
233 public void testOutPort(){
234 assertEquals("outPort", outport, entry.outPort() );
235 }
236
237 @Test
238 public void testFlowEntryUserState(){
239 assertEquals("flowEntryUserState", FlowEntryUserState.FE_USER_ADD, entry.flowEntryUserState() );
240 }
241
242 @Test
243 public void testFlowEntrySwitchState(){
244 assertEquals("flowEntrySwitchState", FlowEntrySwitchState.FE_SWITCH_UPDATED, entry.flowEntrySwitchState() );
245 }
246
247 @Test
248 public void testFlowEntryErrorState(){
249 assertEquals("flowEntryErrorState", errorState, entry.flowEntryErrorState() );
250 }
251
252 @Test
253 public void testToString(){
254 FlowEntry def = new FlowEntry();
Pavlin Radoslavov5139c0b2013-12-09 18:04:53 -0800255 assertEquals("toString", def.toString(), "[ idleTimeout=0 hardTimeout=0 flowEntryActions=[] flowEntryUserState=FE_USER_UNKNOWN flowEntrySwitchState=FE_SWITCH_UNKNOWN]" );
256 assertEquals("toString", entry.toString(), "[flowEntryId=0x5678 flowId=0x1234 idleTimeout=5 hardTimeout=10 flowEntryMatch=[inPort=1 srcMac=01:02:03:04:05:06 dstMac=06:05:04:03:02:01 ethernetFrameType=2 vlanId=3 vlanPriority=4 srcIPv4Net=127.0.0.1/32 dstIPv4Net=127.0.0.2/32 ipProto=5 ipToS=6 srcTcpUdpPort=7 dstTcpUdpPort=8] flowEntryActions=[[type=ACTION_OUTPUT action=[port=9 maxLen=0]];[type=ACTION_OUTPUT action=[port=-3 maxLen=0]];[type=ACTION_SET_VLAN_VID action=[vlanId=3]];[type=ACTION_SET_VLAN_PCP action=[vlanPriority=4]];[type=ACTION_STRIP_VLAN action=[stripVlan=true]];[type=ACTION_SET_DL_SRC action=[addr=01:02:03:04:05:06]];[type=ACTION_SET_DL_DST action=[addr=06:05:04:03:02:01]];[type=ACTION_SET_NW_SRC action=[addr=127.0.0.3]];[type=ACTION_SET_NW_DST action=[addr=127.0.0.4]];[type=ACTION_SET_NW_TOS action=[ipToS=6]];[type=ACTION_SET_TP_SRC action=[port=7]];[type=ACTION_SET_TP_DST action=[port=8]];[type=ACTION_ENQUEUE action=[port=10 queueId=11]];] dpid=00:00:00:00:00:00:ca:fe inPort=1 outPort=9 flowEntryUserState=FE_USER_ADD flowEntrySwitchState=FE_SWITCH_UPDATED flowEntryErrorState=[type=12 code=13]]" );
HIGUCHI Yutad8dc9c02013-08-04 06:16:30 +0900257 }
258
259}