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"); |
| 19 | iFlowPath.setFlowPathFlagsForTest(0L); |
| 20 | iFlowPath.setSrcSwForTest("CA:FE"); |
| 21 | iFlowPath.setSrcPortForTest((short)1); |
| 22 | iFlowPath.setDstSwForTest("BA:BE"); |
| 23 | iFlowPath.setDstPortForTest((short)2); |
| 24 | |
| 25 | iFlowPath.setActionsForTest("[[type=ACTION_OUTPUT action=[port=10 maxLen=11]];[type=ACTION_OUTPUT action=[port=12 maxLen=13]];]"); |
| 26 | |
| 27 | TestFlowEntry iFlowEntry = new TestFlowEntry(); |
| 28 | iFlowEntry.setEntryIdForTest("0x14"); |
| 29 | iFlowEntry.setDpidForTest("BE:EF"); |
| 30 | iFlowEntry.setActionsForTest("[[type=ACTION_OUTPUT action=[port=23 maxLen=24]];[type=ACTION_OUTPUT action=[port=25 maxLen=26]];]"); |
| 31 | iFlowEntry.setUserStateForTest("FE_USER_MODIFY"); |
| 32 | iFlowEntry.setSwitchStateForTest("FE_SWITCH_UPDATE_IN_PROGRESS"); |
| 33 | iFlowPath.addFlowEntryForTest(iFlowEntry); |
| 34 | |
| 35 | flowPath = new FlowPath(iFlowPath); |
| 36 | } |
| 37 | |
| 38 | @Test |
| 39 | public void testFlowPath(){ |
| 40 | FlowPath flowPath = new FlowPath(); |
| 41 | assertFalse( flowPath.flowPathFlags().isDiscardFirstHopEntry() ); |
| 42 | assertFalse( flowPath.flowPathFlags().isKeepOnlyFirstHopEntry() ); |
| 43 | assertTrue( flowPath.flowEntryActions().isEmpty() ); |
| 44 | } |
| 45 | |
| 46 | @Test |
| 47 | public void testFlowPathIFlowPath(){ |
| 48 | TestFlowPath iFlowPath = new TestFlowPath(); |
| 49 | iFlowPath.setFlowIdForTest("0x1234"); |
| 50 | iFlowPath.setInstallerIdForTest("installerId"); |
| 51 | iFlowPath.setFlowPathFlagsForTest(0L); |
| 52 | iFlowPath.setSrcSwForTest("CA:FE"); |
| 53 | iFlowPath.setSrcPortForTest((short)1); |
| 54 | iFlowPath.setDstSwForTest("BA:BE"); |
| 55 | iFlowPath.setDstPortForTest((short)2); |
| 56 | |
| 57 | iFlowPath.setMatchSrcMacForTest("01:02:03:04:05:06"); |
| 58 | iFlowPath.setMatchDstMacForTest("06:05:04:03:02:01"); |
| 59 | iFlowPath.setMatchEthernetFrameTypeForTest((short)3); |
| 60 | iFlowPath.setMatchVlanIdForTest((short)4); |
| 61 | iFlowPath.setMatchVlanPriorityForTest((byte)5); |
| 62 | iFlowPath.setMatchSrcIpaddrForTest("127.0.0.1/32"); |
| 63 | iFlowPath.setMatchDstIpaddrForTest("127.0.0.2/32"); |
| 64 | iFlowPath.setMatchIpProtoForTest((byte)6); |
| 65 | iFlowPath.setMatchIpToSForTest((byte)7); |
| 66 | iFlowPath.setMatchSrcTcpUdpPortForTest((short)8); |
| 67 | iFlowPath.setMatchDstTcpUdpPortForTest((short)9); |
| 68 | |
| 69 | iFlowPath.setActionsForTest("[[type=ACTION_OUTPUT action=[port=10 maxLen=11]];[type=ACTION_OUTPUT action=[port=12 maxLen=13]];]"); |
| 70 | |
| 71 | TestFlowEntry iFlowEntry = new TestFlowEntry(); |
| 72 | iFlowEntry.setEntryIdForTest("0x14"); |
| 73 | iFlowEntry.setDpidForTest("BE:EF"); |
| 74 | iFlowEntry.setMatchInPortForTest((short)15); |
| 75 | iFlowEntry.setMatchSrcMacForTest("11:22:33:44:55:66"); |
| 76 | iFlowEntry.setMatchDstMacForTest("66:55:44:33:22:11"); |
| 77 | iFlowEntry.setMatchEtherFrameTypeForTest((short)16); |
| 78 | iFlowEntry.setMatchVlanIdForTest((short)17); |
| 79 | iFlowEntry.setMatchVlanPriorityForTest((byte)18); |
| 80 | iFlowEntry.setMatchSrcIpaddrForTest("127.0.0.3/32"); |
| 81 | iFlowEntry.setMatchDstIpaddrForTest("127.0.0.4/32"); |
| 82 | iFlowEntry.setMatchIpProtoForTest((byte)19); |
| 83 | iFlowEntry.setMatchIpToSForTest((byte)20); |
| 84 | iFlowEntry.setMatchSrcTcpUdpPortForTest((short)21); |
| 85 | iFlowEntry.setMatchDstTcpUdpPortForTest((short)22); |
| 86 | iFlowEntry.setActionsForTest("[[type=ACTION_OUTPUT action=[port=23 maxLen=24]];[type=ACTION_OUTPUT action=[port=25 maxLen=26]];]"); |
| 87 | iFlowEntry.setUserStateForTest("FE_USER_MODIFY"); |
| 88 | iFlowEntry.setSwitchStateForTest("FE_SWITCH_UPDATE_IN_PROGRESS"); |
| 89 | iFlowPath.addFlowEntryForTest(iFlowEntry); |
| 90 | |
| 91 | FlowPath flowPath = new FlowPath(iFlowPath); |
| 92 | assertEquals(flowPath.flowId().value(), 0x1234); |
| 93 | assertEquals(flowPath.installerId().value(), "installerId"); |
| 94 | assertEquals(flowPath.flowPathFlags().flags(), 0); |
| 95 | assertEquals(flowPath.dataPath().srcPort().dpid().value(), 0xCAFE); |
| 96 | assertEquals(flowPath.dataPath().srcPort().port().value(), 1); |
| 97 | assertEquals(flowPath.dataPath().dstPort().dpid().value(), 0xBABE); |
| 98 | assertEquals(flowPath.dataPath().dstPort().port().value(), 2); |
| 99 | |
| 100 | assertEquals(flowPath.flowEntryMatch().srcMac().toString(), "01:02:03:04:05:06"); |
| 101 | assertEquals(flowPath.flowEntryMatch().dstMac().toString(), "06:05:04:03:02:01"); |
| 102 | assertEquals(flowPath.flowEntryMatch().ethernetFrameType().shortValue(), 3); |
| 103 | assertEquals(flowPath.flowEntryMatch().vlanId().shortValue(), 4); |
| 104 | assertEquals(flowPath.flowEntryMatch().vlanPriority().shortValue(), 5); |
| 105 | assertEquals(flowPath.flowEntryMatch().srcIPv4Net().address().toString(), "127.0.0.1"); |
| 106 | assertEquals(flowPath.flowEntryMatch().srcIPv4Net().prefixLen() , 32); |
| 107 | assertEquals(flowPath.flowEntryMatch().dstIPv4Net().address().toString(), "127.0.0.2"); |
| 108 | assertEquals(flowPath.flowEntryMatch().dstIPv4Net().prefixLen() , 32); |
| 109 | assertEquals(flowPath.flowEntryMatch().ipProto().byteValue(), 6); |
| 110 | assertEquals(flowPath.flowEntryMatch().ipToS().byteValue(), 7); |
| 111 | assertEquals(flowPath.flowEntryMatch().srcTcpUdpPort().shortValue(), 8); |
| 112 | assertEquals(flowPath.flowEntryMatch().dstTcpUdpPort().shortValue(), 9); |
| 113 | |
| 114 | assertEquals(flowPath.flowEntryActions().toString(),"[[type=ACTION_OUTPUT action=[port=10 maxLen=11]];[type=ACTION_OUTPUT action=[port=12 maxLen=13]];]"); |
| 115 | |
| 116 | assertEquals(0x14, flowPath.dataPath().flowEntries().get(0).flowEntryId().value() ); |
| 117 | assertEquals(0xBEEF, flowPath.dataPath().flowEntries().get(0).dpid().value() ); |
| 118 | assertEquals(15, flowPath.dataPath().flowEntries().get(0).flowEntryMatch().inPort().value() ); |
| 119 | assertEquals("11:22:33:44:55:66", flowPath.dataPath().flowEntries().get(0).flowEntryMatch().srcMac().toString()); |
| 120 | assertEquals("66:55:44:33:22:11", flowPath.dataPath().flowEntries().get(0).flowEntryMatch().dstMac().toString()); |
| 121 | assertEquals(16, flowPath.dataPath().flowEntries().get(0).flowEntryMatch().ethernetFrameType().shortValue()); |
| 122 | assertEquals(17, flowPath.dataPath().flowEntries().get(0).flowEntryMatch().vlanId().shortValue()); |
| 123 | assertEquals(18, flowPath.dataPath().flowEntries().get(0).flowEntryMatch().vlanPriority().byteValue()); |
| 124 | assertEquals("127.0.0.3", flowPath.dataPath().flowEntries().get(0).flowEntryMatch().srcIPv4Net().address().toString()); |
| 125 | assertEquals(32, flowPath.dataPath().flowEntries().get(0).flowEntryMatch().srcIPv4Net().prefixLen()); |
| 126 | assertEquals("127.0.0.4", flowPath.dataPath().flowEntries().get(0).flowEntryMatch().dstIPv4Net().address().toString()); |
| 127 | assertEquals(32, flowPath.dataPath().flowEntries().get(0).flowEntryMatch().dstIPv4Net().prefixLen()); |
| 128 | assertEquals(19, flowPath.dataPath().flowEntries().get(0).flowEntryMatch().ipProto().byteValue()); |
| 129 | assertEquals(20, flowPath.dataPath().flowEntries().get(0).flowEntryMatch().ipToS().byteValue()); |
| 130 | assertEquals(21, flowPath.dataPath().flowEntries().get(0).flowEntryMatch().srcTcpUdpPort().shortValue()); |
| 131 | assertEquals(22, flowPath.dataPath().flowEntries().get(0).flowEntryMatch().dstTcpUdpPort().shortValue()); |
| 132 | assertEquals("[[type=ACTION_OUTPUT action=[port=23 maxLen=24]];[type=ACTION_OUTPUT action=[port=25 maxLen=26]];]", flowPath.dataPath().flowEntries().get(0).flowEntryActions().toString()); |
| 133 | assertEquals("FE_USER_MODIFY", flowPath.dataPath().flowEntries().get(0).flowEntryUserState().toString()); |
| 134 | assertEquals("FE_SWITCH_UPDATE_IN_PROGRESS", flowPath.dataPath().flowEntries().get(0).flowEntrySwitchState().toString()); |
| 135 | } |
| 136 | |
| 137 | |
| 138 | @Test |
| 139 | public void testFlowPathFlags(){ |
| 140 | FlowPath flowPath = new FlowPath(); |
| 141 | FlowPathFlags flags = new FlowPathFlags(); |
| 142 | flags.setFlags(0); |
| 143 | flowPath.setFlowPathFlags( flags ); |
| 144 | assertFalse( flowPath.flowPathFlags().isDiscardFirstHopEntry() ); |
| 145 | assertFalse( flowPath.flowPathFlags().isKeepOnlyFirstHopEntry() ); |
| 146 | } |
| 147 | |
| 148 | @Test |
| 149 | public void testSetFlowPathFlags(){ |
| 150 | FlowPath flowPath = new FlowPath(); |
| 151 | FlowPathFlags flags = new FlowPathFlags("DISCARD_FIRST_HOP_ENTRY"); |
| 152 | flags.setFlagsStr("KEEP_ONLY_FIRST_HOP_ENTRY"); |
| 153 | flowPath.setFlowPathFlags( flags ); |
| 154 | assertFalse( flowPath.flowPathFlags().isDiscardFirstHopEntry() ); |
| 155 | assertTrue( flowPath.flowPathFlags().isKeepOnlyFirstHopEntry() ); |
| 156 | } |
| 157 | |
| 158 | @Test |
| 159 | public void testSetDataPath(){ |
| 160 | FlowPath flowPath = new FlowPath(); |
| 161 | DataPath dataPath = new DataPath(); |
| 162 | flowPath.setDataPath( dataPath ); |
| 163 | assertEquals(flowPath.dataPath(), dataPath ); |
| 164 | } |
| 165 | |
| 166 | @Test |
| 167 | public void testToString(){ |
| 168 | |
HIGUCHI Yuta | 64163c0 | 2013-08-06 07:51:19 +0900 | [diff] [blame] | 169 | assertEquals("[flowId=0x1234 installerId=installerId flowPathFlags=[flags=] dataPath=[src=00:00:00:00:00:00:ca:fe/1 flowEntry=[flowEntryId=0x14 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] | 170 | } |
| 171 | |
| 172 | @Test |
| 173 | public void testCompareTo(){ |
| 174 | FlowPath flowPath1 = new FlowPath(); |
| 175 | flowPath1.setFlowId( new FlowId(1)); |
| 176 | FlowPath flowPath2 = new FlowPath(); |
| 177 | flowPath2.setFlowId( new FlowId(2)); |
| 178 | |
| 179 | assertTrue( flowPath1.compareTo(flowPath2) < 0); |
| 180 | } |
| 181 | |
| 182 | } |