blob: 1d193c4f442ec0104a5dd3dea84c278cf23d27f3 [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
147 public void testGetFlowId(){
148 assertEquals("flowId", flowId, entry.getFlowId() );
149 }
150
151 @Test
152 public void testFlowEntryId(){
153 assertEquals("flowEntryId", flowEntryId, entry.flowEntryId() );
154 }
155
156 @Test
157 public void testFlowEntryMatch(){
158 assertEquals("flowEntryMatch", match, entry.flowEntryMatch() );
159 }
160
161 @Test
162 public void testFlowEntryActions(){
163 assertEquals("flowEntryActions", actions, entry.flowEntryActions() );
164 }
165
166 @Test
167 public void testSetFlowEntryActions(){
168 FlowEntryActions actions = new FlowEntryActions();
169 entry.setFlowEntryActions( actions );
170 assertEquals("flowEntryActions", actions, entry.flowEntryActions() );
171 }
172
173 @Test
174 public void testDpid(){
175 assertEquals("dpid", dpid, entry.dpid() );
176 }
177
178 @Test
179 public void testInPort(){
180 assertEquals("inPort", inport, entry.inPort() );
181 }
182
183 @Test
184 public void testOutPort(){
185 assertEquals("outPort", outport, entry.outPort() );
186 }
187
188 @Test
189 public void testFlowEntryUserState(){
190 assertEquals("flowEntryUserState", FlowEntryUserState.FE_USER_ADD, entry.flowEntryUserState() );
191 }
192
193 @Test
194 public void testFlowEntrySwitchState(){
195 assertEquals("flowEntrySwitchState", FlowEntrySwitchState.FE_SWITCH_UPDATED, entry.flowEntrySwitchState() );
196 }
197
198 @Test
199 public void testFlowEntryErrorState(){
200 assertEquals("flowEntryErrorState", errorState, entry.flowEntryErrorState() );
201 }
202
203 @Test
204 public void testToString(){
205 FlowEntry def = new FlowEntry();
HIGUCHI Yuta64163c02013-08-06 07:51:19 +0900206 assertEquals( def.toString(), "[ flowEntryActions=[] flowEntryUserState=FE_USER_UNKNOWN flowEntrySwitchState=FE_SWITCH_UNKNOWN]" );
HIGUCHI Yutad8dc9c02013-08-04 06:16:30 +0900207 assertEquals( 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]]" );
208 }
209
210}