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.*; |
| 4 | import net.onrc.onos.ofcontroller.core.internal.TestableGraphDBOperation.TestFlowEntry; |
| 5 | import net.onrc.onos.ofcontroller.core.internal.TestableGraphDBOperation.TestFlowPath; |
| 6 | |
| 7 | import org.junit.Before; |
| 8 | import org.junit.Test; |
| 9 | |
| 10 | public 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 Radoslavov | d28cf7c | 2013-10-26 11:27:43 -0700 | [diff] [blame] | 19 | iFlowPath.setFlowPathTypeForTest("FP_TYPE_SHORTEST_PATH"); |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 20 | iFlowPath.setFlowPathUserStateForTest("FP_USER_ADD"); |
HIGUCHI Yuta | d8dc9c0 | 2013-08-04 06:16:30 +0900 | [diff] [blame] | 21 | iFlowPath.setFlowPathFlagsForTest(0L); |
Pavlin Radoslavov | 5139c0b | 2013-12-09 18:04:53 -0800 | [diff] [blame] | 22 | iFlowPath.setIdleTimeoutForTest(5); |
| 23 | iFlowPath.setHardTimeoutForTest(10); |
HIGUCHI Yuta | d8dc9c0 | 2013-08-04 06:16:30 +0900 | [diff] [blame] | 24 | iFlowPath.setSrcSwForTest("CA:FE"); |
| 25 | iFlowPath.setSrcPortForTest((short)1); |
| 26 | iFlowPath.setDstSwForTest("BA:BE"); |
| 27 | iFlowPath.setDstPortForTest((short)2); |
| 28 | |
| 29 | iFlowPath.setActionsForTest("[[type=ACTION_OUTPUT action=[port=10 maxLen=11]];[type=ACTION_OUTPUT action=[port=12 maxLen=13]];]"); |
| 30 | |
| 31 | TestFlowEntry iFlowEntry = new TestFlowEntry(); |
| 32 | iFlowEntry.setEntryIdForTest("0x14"); |
| 33 | iFlowEntry.setDpidForTest("BE:EF"); |
| 34 | iFlowEntry.setActionsForTest("[[type=ACTION_OUTPUT action=[port=23 maxLen=24]];[type=ACTION_OUTPUT action=[port=25 maxLen=26]];]"); |
| 35 | iFlowEntry.setUserStateForTest("FE_USER_MODIFY"); |
| 36 | iFlowEntry.setSwitchStateForTest("FE_SWITCH_UPDATE_IN_PROGRESS"); |
| 37 | iFlowPath.addFlowEntryForTest(iFlowEntry); |
| 38 | |
| 39 | flowPath = new FlowPath(iFlowPath); |
| 40 | } |
| 41 | |
| 42 | @Test |
| 43 | public void testFlowPath(){ |
| 44 | FlowPath flowPath = new FlowPath(); |
Pavlin Radoslavov | d28cf7c | 2013-10-26 11:27:43 -0700 | [diff] [blame] | 45 | assertTrue ( flowPath.flowPathType() == FlowPathType.FP_TYPE_UNKNOWN); |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 46 | assertTrue ( flowPath.flowPathUserState() == FlowPathUserState.FP_USER_UNKNOWN); |
HIGUCHI Yuta | d8dc9c0 | 2013-08-04 06:16:30 +0900 | [diff] [blame] | 47 | assertFalse( flowPath.flowPathFlags().isDiscardFirstHopEntry() ); |
| 48 | assertFalse( flowPath.flowPathFlags().isKeepOnlyFirstHopEntry() ); |
Pavlin Radoslavov | 5139c0b | 2013-12-09 18:04:53 -0800 | [diff] [blame] | 49 | assertTrue (flowPath.idleTimeout() == 0); |
| 50 | assertTrue (flowPath.hardTimeout() == 0); |
HIGUCHI Yuta | d8dc9c0 | 2013-08-04 06:16:30 +0900 | [diff] [blame] | 51 | assertTrue( flowPath.flowEntryActions().isEmpty() ); |
| 52 | } |
| 53 | |
| 54 | @Test |
| 55 | public void testFlowPathIFlowPath(){ |
| 56 | TestFlowPath iFlowPath = new TestFlowPath(); |
| 57 | iFlowPath.setFlowIdForTest("0x1234"); |
| 58 | iFlowPath.setInstallerIdForTest("installerId"); |
Pavlin Radoslavov | d28cf7c | 2013-10-26 11:27:43 -0700 | [diff] [blame] | 59 | iFlowPath.setFlowPathTypeForTest("FP_TYPE_SHORTEST_PATH"); |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 60 | iFlowPath.setFlowPathUserStateForTest("FP_USER_ADD"); |
HIGUCHI Yuta | d8dc9c0 | 2013-08-04 06:16:30 +0900 | [diff] [blame] | 61 | iFlowPath.setFlowPathFlagsForTest(0L); |
Pavlin Radoslavov | 5139c0b | 2013-12-09 18:04:53 -0800 | [diff] [blame] | 62 | iFlowPath.setIdleTimeoutForTest(5); |
| 63 | iFlowPath.setHardTimeoutForTest(10); |
HIGUCHI Yuta | d8dc9c0 | 2013-08-04 06:16:30 +0900 | [diff] [blame] | 64 | iFlowPath.setSrcSwForTest("CA:FE"); |
| 65 | iFlowPath.setSrcPortForTest((short)1); |
| 66 | iFlowPath.setDstSwForTest("BA:BE"); |
| 67 | iFlowPath.setDstPortForTest((short)2); |
| 68 | |
| 69 | iFlowPath.setMatchSrcMacForTest("01:02:03:04:05:06"); |
| 70 | iFlowPath.setMatchDstMacForTest("06:05:04:03:02:01"); |
| 71 | iFlowPath.setMatchEthernetFrameTypeForTest((short)3); |
| 72 | iFlowPath.setMatchVlanIdForTest((short)4); |
| 73 | iFlowPath.setMatchVlanPriorityForTest((byte)5); |
| 74 | iFlowPath.setMatchSrcIpaddrForTest("127.0.0.1/32"); |
| 75 | iFlowPath.setMatchDstIpaddrForTest("127.0.0.2/32"); |
| 76 | iFlowPath.setMatchIpProtoForTest((byte)6); |
| 77 | iFlowPath.setMatchIpToSForTest((byte)7); |
| 78 | iFlowPath.setMatchSrcTcpUdpPortForTest((short)8); |
| 79 | iFlowPath.setMatchDstTcpUdpPortForTest((short)9); |
| 80 | |
| 81 | iFlowPath.setActionsForTest("[[type=ACTION_OUTPUT action=[port=10 maxLen=11]];[type=ACTION_OUTPUT action=[port=12 maxLen=13]];]"); |
| 82 | |
| 83 | TestFlowEntry iFlowEntry = new TestFlowEntry(); |
| 84 | iFlowEntry.setEntryIdForTest("0x14"); |
| 85 | iFlowEntry.setDpidForTest("BE:EF"); |
| 86 | iFlowEntry.setMatchInPortForTest((short)15); |
| 87 | iFlowEntry.setMatchSrcMacForTest("11:22:33:44:55:66"); |
| 88 | iFlowEntry.setMatchDstMacForTest("66:55:44:33:22:11"); |
| 89 | iFlowEntry.setMatchEtherFrameTypeForTest((short)16); |
| 90 | iFlowEntry.setMatchVlanIdForTest((short)17); |
| 91 | iFlowEntry.setMatchVlanPriorityForTest((byte)18); |
| 92 | iFlowEntry.setMatchSrcIpaddrForTest("127.0.0.3/32"); |
| 93 | iFlowEntry.setMatchDstIpaddrForTest("127.0.0.4/32"); |
| 94 | iFlowEntry.setMatchIpProtoForTest((byte)19); |
| 95 | iFlowEntry.setMatchIpToSForTest((byte)20); |
| 96 | iFlowEntry.setMatchSrcTcpUdpPortForTest((short)21); |
| 97 | iFlowEntry.setMatchDstTcpUdpPortForTest((short)22); |
| 98 | iFlowEntry.setActionsForTest("[[type=ACTION_OUTPUT action=[port=23 maxLen=24]];[type=ACTION_OUTPUT action=[port=25 maxLen=26]];]"); |
| 99 | iFlowEntry.setUserStateForTest("FE_USER_MODIFY"); |
| 100 | iFlowEntry.setSwitchStateForTest("FE_SWITCH_UPDATE_IN_PROGRESS"); |
| 101 | iFlowPath.addFlowEntryForTest(iFlowEntry); |
| 102 | |
| 103 | FlowPath flowPath = new FlowPath(iFlowPath); |
| 104 | assertEquals(flowPath.flowId().value(), 0x1234); |
| 105 | assertEquals(flowPath.installerId().value(), "installerId"); |
Pavlin Radoslavov | d28cf7c | 2013-10-26 11:27:43 -0700 | [diff] [blame] | 106 | assertEquals(flowPath.flowPathType(), FlowPathType.FP_TYPE_SHORTEST_PATH); |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 107 | assertEquals(flowPath.flowPathUserState(), FlowPathUserState.FP_USER_ADD); |
HIGUCHI Yuta | d8dc9c0 | 2013-08-04 06:16:30 +0900 | [diff] [blame] | 108 | assertEquals(flowPath.flowPathFlags().flags(), 0); |
Pavlin Radoslavov | 5139c0b | 2013-12-09 18:04:53 -0800 | [diff] [blame] | 109 | assertEquals(flowPath.idleTimeout(), 5); |
| 110 | assertEquals(flowPath.hardTimeout(), 10); |
HIGUCHI Yuta | d8dc9c0 | 2013-08-04 06:16:30 +0900 | [diff] [blame] | 111 | assertEquals(flowPath.dataPath().srcPort().dpid().value(), 0xCAFE); |
| 112 | assertEquals(flowPath.dataPath().srcPort().port().value(), 1); |
| 113 | assertEquals(flowPath.dataPath().dstPort().dpid().value(), 0xBABE); |
| 114 | assertEquals(flowPath.dataPath().dstPort().port().value(), 2); |
| 115 | |
| 116 | assertEquals(flowPath.flowEntryMatch().srcMac().toString(), "01:02:03:04:05:06"); |
| 117 | assertEquals(flowPath.flowEntryMatch().dstMac().toString(), "06:05:04:03:02:01"); |
| 118 | assertEquals(flowPath.flowEntryMatch().ethernetFrameType().shortValue(), 3); |
| 119 | assertEquals(flowPath.flowEntryMatch().vlanId().shortValue(), 4); |
| 120 | assertEquals(flowPath.flowEntryMatch().vlanPriority().shortValue(), 5); |
| 121 | assertEquals(flowPath.flowEntryMatch().srcIPv4Net().address().toString(), "127.0.0.1"); |
| 122 | assertEquals(flowPath.flowEntryMatch().srcIPv4Net().prefixLen() , 32); |
| 123 | assertEquals(flowPath.flowEntryMatch().dstIPv4Net().address().toString(), "127.0.0.2"); |
| 124 | assertEquals(flowPath.flowEntryMatch().dstIPv4Net().prefixLen() , 32); |
| 125 | assertEquals(flowPath.flowEntryMatch().ipProto().byteValue(), 6); |
| 126 | assertEquals(flowPath.flowEntryMatch().ipToS().byteValue(), 7); |
| 127 | assertEquals(flowPath.flowEntryMatch().srcTcpUdpPort().shortValue(), 8); |
| 128 | assertEquals(flowPath.flowEntryMatch().dstTcpUdpPort().shortValue(), 9); |
| 129 | |
| 130 | assertEquals(flowPath.flowEntryActions().toString(),"[[type=ACTION_OUTPUT action=[port=10 maxLen=11]];[type=ACTION_OUTPUT action=[port=12 maxLen=13]];]"); |
| 131 | |
| 132 | assertEquals(0x14, flowPath.dataPath().flowEntries().get(0).flowEntryId().value() ); |
| 133 | assertEquals(0xBEEF, flowPath.dataPath().flowEntries().get(0).dpid().value() ); |
Pavlin Radoslavov | 5139c0b | 2013-12-09 18:04:53 -0800 | [diff] [blame] | 134 | assertEquals(0, flowPath.dataPath().flowEntries().get(0).idleTimeout() ); |
| 135 | assertEquals(0, flowPath.dataPath().flowEntries().get(0).hardTimeout() ); |
HIGUCHI Yuta | d8dc9c0 | 2013-08-04 06:16:30 +0900 | [diff] [blame] | 136 | assertEquals(15, flowPath.dataPath().flowEntries().get(0).flowEntryMatch().inPort().value() ); |
| 137 | assertEquals("11:22:33:44:55:66", flowPath.dataPath().flowEntries().get(0).flowEntryMatch().srcMac().toString()); |
| 138 | assertEquals("66:55:44:33:22:11", flowPath.dataPath().flowEntries().get(0).flowEntryMatch().dstMac().toString()); |
| 139 | assertEquals(16, flowPath.dataPath().flowEntries().get(0).flowEntryMatch().ethernetFrameType().shortValue()); |
| 140 | assertEquals(17, flowPath.dataPath().flowEntries().get(0).flowEntryMatch().vlanId().shortValue()); |
| 141 | assertEquals(18, flowPath.dataPath().flowEntries().get(0).flowEntryMatch().vlanPriority().byteValue()); |
| 142 | assertEquals("127.0.0.3", flowPath.dataPath().flowEntries().get(0).flowEntryMatch().srcIPv4Net().address().toString()); |
| 143 | assertEquals(32, flowPath.dataPath().flowEntries().get(0).flowEntryMatch().srcIPv4Net().prefixLen()); |
| 144 | assertEquals("127.0.0.4", flowPath.dataPath().flowEntries().get(0).flowEntryMatch().dstIPv4Net().address().toString()); |
| 145 | assertEquals(32, flowPath.dataPath().flowEntries().get(0).flowEntryMatch().dstIPv4Net().prefixLen()); |
| 146 | assertEquals(19, flowPath.dataPath().flowEntries().get(0).flowEntryMatch().ipProto().byteValue()); |
| 147 | assertEquals(20, flowPath.dataPath().flowEntries().get(0).flowEntryMatch().ipToS().byteValue()); |
| 148 | assertEquals(21, flowPath.dataPath().flowEntries().get(0).flowEntryMatch().srcTcpUdpPort().shortValue()); |
| 149 | assertEquals(22, flowPath.dataPath().flowEntries().get(0).flowEntryMatch().dstTcpUdpPort().shortValue()); |
| 150 | assertEquals("[[type=ACTION_OUTPUT action=[port=23 maxLen=24]];[type=ACTION_OUTPUT action=[port=25 maxLen=26]];]", flowPath.dataPath().flowEntries().get(0).flowEntryActions().toString()); |
| 151 | assertEquals("FE_USER_MODIFY", flowPath.dataPath().flowEntries().get(0).flowEntryUserState().toString()); |
| 152 | assertEquals("FE_SWITCH_UPDATE_IN_PROGRESS", flowPath.dataPath().flowEntries().get(0).flowEntrySwitchState().toString()); |
| 153 | } |
| 154 | |
Pavlin Radoslavov | d28cf7c | 2013-10-26 11:27:43 -0700 | [diff] [blame] | 155 | @Test |
| 156 | public void testSetFlowPathType(){ |
| 157 | FlowPath flowPath = new FlowPath(); |
| 158 | FlowPathType type = FlowPathType.FP_TYPE_SHORTEST_PATH; |
| 159 | flowPath.setFlowPathType( type ); |
| 160 | assertTrue( flowPath.flowPathType() == FlowPathType.FP_TYPE_SHORTEST_PATH ); |
| 161 | } |
HIGUCHI Yuta | d8dc9c0 | 2013-08-04 06:16:30 +0900 | [diff] [blame] | 162 | |
| 163 | @Test |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 164 | public void testSetFlowPathUserState(){ |
| 165 | FlowPath flowPath = new FlowPath(); |
| 166 | FlowPathUserState state = FlowPathUserState.FP_USER_ADD; |
| 167 | flowPath.setFlowPathUserState( state ); |
| 168 | assertTrue( flowPath.flowPathUserState() == FlowPathUserState.FP_USER_ADD ); |
| 169 | } |
| 170 | |
| 171 | @Test |
HIGUCHI Yuta | d8dc9c0 | 2013-08-04 06:16:30 +0900 | [diff] [blame] | 172 | public void testFlowPathFlags(){ |
| 173 | FlowPath flowPath = new FlowPath(); |
| 174 | FlowPathFlags flags = new FlowPathFlags(); |
| 175 | flags.setFlags(0); |
| 176 | flowPath.setFlowPathFlags( flags ); |
| 177 | assertFalse( flowPath.flowPathFlags().isDiscardFirstHopEntry() ); |
| 178 | assertFalse( flowPath.flowPathFlags().isKeepOnlyFirstHopEntry() ); |
| 179 | } |
| 180 | |
| 181 | @Test |
| 182 | public void testSetFlowPathFlags(){ |
| 183 | FlowPath flowPath = new FlowPath(); |
| 184 | FlowPathFlags flags = new FlowPathFlags("DISCARD_FIRST_HOP_ENTRY"); |
| 185 | flags.setFlagsStr("KEEP_ONLY_FIRST_HOP_ENTRY"); |
| 186 | flowPath.setFlowPathFlags( flags ); |
| 187 | assertFalse( flowPath.flowPathFlags().isDiscardFirstHopEntry() ); |
| 188 | assertTrue( flowPath.flowPathFlags().isKeepOnlyFirstHopEntry() ); |
| 189 | } |
| 190 | |
| 191 | @Test |
Pavlin Radoslavov | 5139c0b | 2013-12-09 18:04:53 -0800 | [diff] [blame] | 192 | public void testSetIdleTimeout(){ |
| 193 | FlowPath flowPath = new FlowPath(); |
| 194 | int idleTimeout = 15; |
| 195 | flowPath.setIdleTimeout( idleTimeout ); |
| 196 | assertTrue( flowPath.idleTimeout() == 15 ); |
| 197 | } |
| 198 | |
| 199 | @Test |
| 200 | public void testSetHardTimeout(){ |
| 201 | FlowPath flowPath = new FlowPath(); |
| 202 | int hardTimeout = 20; |
| 203 | flowPath.setHardTimeout( hardTimeout ); |
| 204 | assertTrue( flowPath.hardTimeout() == 20 ); |
| 205 | } |
| 206 | |
| 207 | @Test |
HIGUCHI Yuta | d8dc9c0 | 2013-08-04 06:16:30 +0900 | [diff] [blame] | 208 | public void testSetDataPath(){ |
| 209 | FlowPath flowPath = new FlowPath(); |
| 210 | DataPath dataPath = new DataPath(); |
| 211 | flowPath.setDataPath( dataPath ); |
| 212 | assertEquals(flowPath.dataPath(), dataPath ); |
| 213 | } |
| 214 | |
| 215 | @Test |
| 216 | public void testToString(){ |
| 217 | |
Pavlin Radoslavov | 5139c0b | 2013-12-09 18:04:53 -0800 | [diff] [blame] | 218 | assertEquals("[flowId=0x1234 installerId=installerId flowPathType=FP_TYPE_SHORTEST_PATH flowPathUserState=FP_USER_ADD flowPathFlags=[flags=] idleTimeout=5 hardTimeout=10 dataPath=[src=00:00:00:00:00:00:ca:fe/1 flowEntry=[flowEntryId=0x14 idleTimeout=0 hardTimeout=0 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 Yuta | d8dc9c0 | 2013-08-04 06:16:30 +0900 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | @Test |
| 222 | public void testCompareTo(){ |
| 223 | FlowPath flowPath1 = new FlowPath(); |
| 224 | flowPath1.setFlowId( new FlowId(1)); |
| 225 | FlowPath flowPath2 = new FlowPath(); |
| 226 | flowPath2.setFlowId( new FlowId(2)); |
| 227 | |
| 228 | assertTrue( flowPath1.compareTo(flowPath2) < 0); |
| 229 | } |
| 230 | |
| 231 | } |