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