blob: 7385b25cd159a75abf0fb577f4c82381671b2945 [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);
16 FlowEntryMatch match;
17 FlowEntryActions actions;
18
19 Dpid dpid = new Dpid(0xCAFE);
20
21 Port inport = new Port((short)1);
22 byte[] byte1 = { 1, 2, 3, 4, 5, 6 };
23 byte[] byte2 = { 6, 5, 4, 3, 2, 1 };
24 MACAddress mac1 = new MACAddress(byte1);
25 MACAddress mac2 = new MACAddress(byte2);
26 Short ether = Short.valueOf((short)2);
27 Short vlanid = Short.valueOf((short)3);
28 Byte vlanprio = Byte.valueOf((byte)4);
29 IPv4Net ip1 = new IPv4Net("127.0.0.1/32");
30 IPv4Net ip2 = new IPv4Net( new IPv4("127.0.0.2"), (short)32);
31 IPv4 ipaddr1 = new IPv4("127.0.0.3");
32 IPv4 ipaddr2 = new IPv4("127.0.0.4");
33 Byte ipproto = Byte.valueOf((byte)5);
34 Byte ipToS = Byte.valueOf((byte)6);
35 Short tport1 = Short.valueOf((short)7);
36 Short tport2 = Short.valueOf((short)8);
37 Port outport = new Port((short)9);
38 Port queueport = new Port((short)10);
39 int queueId = 11;
40
41 FlowEntryErrorState errorState = new FlowEntryErrorState( (short)12, (short)13);
42
43
44 @Before
45 public void setUp() throws Exception{
46 entry = new FlowEntry();
47
48 flowId = new FlowId("0x1234");
49 entry.setFlowId( flowId );
50
51 flowEntryId = new FlowEntryId("0x5678");
52 entry.setFlowEntryId(flowEntryId);
53
54 dpid = new Dpid("CA:FE");
55 entry.setDpid( dpid );
56
57 entry.setInPort( inport );
58 entry.setOutPort( outport );
59
60 match = new FlowEntryMatch();
61 match.enableInPort( inport);
62 match.enableSrcMac( mac1 );
63 match.enableDstMac( mac2 );
64 match.enableEthernetFrameType( ether );
65 match.enableVlanId( vlanid );
66 match.enableVlanPriority( vlanprio );
67 match.enableSrcIPv4Net( ip1 );
68 match.enableDstIPv4Net( ip2 );
69 match.enableIpProto( ipproto );
70 match.enableIpToS( ipToS );
71 match.enableSrcTcpUdpPort( tport1 );
72 match.enableDstTcpUdpPort( tport2 );
73
74 entry.setFlowEntryMatch( match );
75
76 FlowEntryAction action = null;
77 actions = entry.flowEntryActions();
78
79 action = new FlowEntryAction();
80 action.setActionOutput(outport);
81 actions.addAction(action);
82
83 action = new FlowEntryAction();
84 action.setActionOutputToController((short)0);
85 actions.addAction(action);
86
87 action = new FlowEntryAction();
88 action.setActionSetVlanId(vlanid);
89 actions.addAction(action);
90
91 action = new FlowEntryAction();
92 action.setActionSetVlanPriority(vlanprio);
93 actions.addAction(action);
94
95 action = new FlowEntryAction();
96 action.setActionStripVlan(true);
97 actions.addAction(action);
98
99 action = new FlowEntryAction();
100 action.setActionSetEthernetSrcAddr(mac1);
101 actions.addAction(action);
102
103 action = new FlowEntryAction();
104 action.setActionSetEthernetDstAddr(mac2);
105 actions.addAction(action);
106
107 action = new FlowEntryAction();
108 action.setActionSetIPv4SrcAddr(ipaddr1);
109 actions.addAction(action);
110
111 action = new FlowEntryAction();
112 action.setActionSetIPv4DstAddr(ipaddr2);
113 actions.addAction(action);
114
115 action = new FlowEntryAction();
116 action.setActionSetIpToS(ipToS);
117 actions.addAction(action);
118
119 action = new FlowEntryAction();
120 action.setActionSetTcpUdpSrcPort(tport1);
121 actions.addAction(action);
122
123 action = new FlowEntryAction();
124 action.setActionSetTcpUdpDstPort(tport2);
125 actions.addAction(action);
126
127 action = new FlowEntryAction();
128 action.setActionEnqueue(queueport, queueId);
129 actions.addAction(action);
130
131 entry.setFlowEntryUserState( FlowEntryUserState.FE_USER_ADD );
132 entry.setFlowEntrySwitchState( FlowEntrySwitchState.FE_SWITCH_UPDATED );
133 entry.setFlowEntryErrorState( errorState );
134
135 }
136
137 @Test
138 public void testFlowEntry(){
139 FlowEntry e = new FlowEntry();
140
141 assertTrue( e.flowEntryActions().isEmpty() );
142 assertEquals("flowEntryUserState", FlowEntryUserState.FE_USER_UNKNOWN, e.flowEntryUserState() );
143 assertEquals("flowEntrySwitchState", FlowEntrySwitchState.FE_SWITCH_UNKNOWN, e.flowEntrySwitchState() );
144 }
145
146 @Test
Pavlin Radoslavovb1309e82013-10-30 12:18:28 -0700147 public void testFlowId(){
148 assertEquals("flowId", flowId, entry.flowId() );
HIGUCHI Yutad8dc9c02013-08-04 06:16:30 +0900149 }
150
151 @Test
Pavlin Radoslavov062c72d2013-10-30 12:42:15 -0700152 public void testIsValidFlowId(){
153 FlowEntry e = new FlowEntry();
154
155 // Test a Flow Entry with empty Flow ID
156 assertEquals("isValidFlowId", false, e.isValidFlowId() );
157
158 // Test a Flow Entry with invalid Flow ID
159 e.setFlowId(new FlowId());
160 assertEquals("isValidFlowId", false, e.isValidFlowId() );
161
162 // Test a Flow Entry with valid Flow ID
163 e.setFlowId(new FlowId(0x1));
164 assertEquals("isValidFlowId", true, e.isValidFlowId() );
165 assertEquals("isValidFlowId", true, entry.isValidFlowId() );
166 }
167
168 @Test
HIGUCHI Yutad8dc9c02013-08-04 06:16:30 +0900169 public void testFlowEntryId(){
170 assertEquals("flowEntryId", flowEntryId, entry.flowEntryId() );
171 }
172
173 @Test
Pavlin Radoslavovb1309e82013-10-30 12:18:28 -0700174 public void testIsValidFlowEntryId(){
175 FlowEntry e = new FlowEntry();
176
177 // Test a Flow Entry with empty Flow Entry ID
178 assertEquals("isValidFlowEntryId", false, e.isValidFlowEntryId() );
179
180 // Test a Flow Entry with invalid Flow Entry ID
181 e.setFlowEntryId(new FlowEntryId());
182 assertEquals("isValidFlowEntryId", false, e.isValidFlowEntryId() );
183
184 // Test a Flow Entry with valid Flow Entry ID
185 e.setFlowEntryId(new FlowEntryId(0x1));
186 assertEquals("isValidFlowEntryId", true, e.isValidFlowEntryId() );
187 assertEquals("isValidFlowEntryId", true, entry.isValidFlowEntryId() );
188 }
189
190 @Test
HIGUCHI Yutad8dc9c02013-08-04 06:16:30 +0900191 public void testFlowEntryMatch(){
192 assertEquals("flowEntryMatch", match, entry.flowEntryMatch() );
193 }
194
195 @Test
196 public void testFlowEntryActions(){
197 assertEquals("flowEntryActions", actions, entry.flowEntryActions() );
198 }
199
200 @Test
201 public void testSetFlowEntryActions(){
202 FlowEntryActions actions = new FlowEntryActions();
203 entry.setFlowEntryActions( actions );
204 assertEquals("flowEntryActions", actions, entry.flowEntryActions() );
205 }
206
207 @Test
208 public void testDpid(){
209 assertEquals("dpid", dpid, entry.dpid() );
210 }
211
212 @Test
213 public void testInPort(){
214 assertEquals("inPort", inport, entry.inPort() );
215 }
216
217 @Test
218 public void testOutPort(){
219 assertEquals("outPort", outport, entry.outPort() );
220 }
221
222 @Test
223 public void testFlowEntryUserState(){
224 assertEquals("flowEntryUserState", FlowEntryUserState.FE_USER_ADD, entry.flowEntryUserState() );
225 }
226
227 @Test
228 public void testFlowEntrySwitchState(){
229 assertEquals("flowEntrySwitchState", FlowEntrySwitchState.FE_SWITCH_UPDATED, entry.flowEntrySwitchState() );
230 }
231
232 @Test
233 public void testFlowEntryErrorState(){
234 assertEquals("flowEntryErrorState", errorState, entry.flowEntryErrorState() );
235 }
236
237 @Test
238 public void testToString(){
239 FlowEntry def = new FlowEntry();
Pavlin Radoslavovb1309e82013-10-30 12:18:28 -0700240 assertEquals("toString", def.toString(), "[ flowEntryActions=[] flowEntryUserState=FE_USER_UNKNOWN flowEntrySwitchState=FE_SWITCH_UNKNOWN]" );
241 assertEquals("toString", entry.toString(), "[flowEntryId=0x5678 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 +0900242 }
243
244}