Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Foundation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Carmelo Cascone | 356ab8b | 2019-09-25 01:02:53 -0700 | [diff] [blame] | 17 | package org.onosproject.pipelines.fabric.impl.behaviour.pipeliner; |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 18 | |
| 19 | import org.junit.Ignore; |
| 20 | import org.junit.Test; |
| 21 | import org.onlab.packet.Ethernet; |
| 22 | import org.onlab.packet.IpPrefix; |
| 23 | import org.onlab.packet.MacAddress; |
| 24 | import org.onlab.packet.MplsLabel; |
| 25 | import org.onlab.packet.VlanId; |
| 26 | import org.onosproject.TestApplicationId; |
| 27 | import org.onosproject.core.ApplicationId; |
| 28 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 29 | import org.onosproject.net.flow.TrafficSelector; |
| 30 | import org.onosproject.net.flowobjective.DefaultForwardingObjective; |
| 31 | import org.onosproject.net.flowobjective.ForwardingObjective; |
| 32 | |
| 33 | import static org.junit.Assert.assertEquals; |
| 34 | |
| 35 | /** |
| 36 | * Unit tests for Forwarding class. |
| 37 | */ |
| 38 | public class ForwardingFunctionTypeTest { |
| 39 | private static final ApplicationId APP_ID = TestApplicationId.create("ForwardingFunctionTypeTest"); |
| 40 | private static final VlanId VLAN_100 = VlanId.vlanId((short) 100); |
| 41 | private static final MacAddress MAC_ADDR = MacAddress.valueOf("00:00:00:00:00:01"); |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 42 | private static final MacAddress MAC_NONE = MacAddress.NONE; |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 43 | private static final IpPrefix IPV4_UNICAST_ADDR = IpPrefix.valueOf("10.0.0.1/32"); |
| 44 | private static final IpPrefix IPV4_MCAST_ADDR = IpPrefix.valueOf("224.0.0.1/32"); |
| 45 | private static final IpPrefix IPV6_UNICAST_ADDR = IpPrefix.valueOf("2000::1/32"); |
| 46 | private static final IpPrefix IPV6_MCAST_ADDR = IpPrefix.valueOf("ff00::1/32"); |
| 47 | private static final MplsLabel MPLS_10 = MplsLabel.mplsLabel(10); |
| 48 | private TrafficSelector selector; |
| 49 | |
| 50 | /** |
| 51 | * Match Vlan + EthDst. |
| 52 | */ |
| 53 | @Test |
| 54 | public void testL2Unicast() { |
| 55 | selector = DefaultTrafficSelector.builder() |
| 56 | .matchVlanId(VLAN_100) |
| 57 | .matchEthDst(MAC_ADDR) |
| 58 | .build(); |
| 59 | testFft(selector, ForwardingFunctionType.L2_UNICAST); |
| 60 | } |
| 61 | |
| 62 | @Test |
| 63 | public void testL2Broadcast() { |
| 64 | selector = DefaultTrafficSelector.builder() |
| 65 | .matchVlanId(VLAN_100) |
| 66 | .build(); |
| 67 | testFft(selector, ForwardingFunctionType.L2_BROADCAST); |
| 68 | } |
| 69 | |
| 70 | @Test |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 71 | public void testL2BroadcastWithMacNone() { |
| 72 | selector = DefaultTrafficSelector.builder() |
| 73 | .matchVlanId(VLAN_100) |
| 74 | .matchEthDst(MAC_NONE) |
| 75 | .build(); |
| 76 | testFft(selector, ForwardingFunctionType.L2_BROADCAST); |
| 77 | } |
| 78 | |
| 79 | @Test |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 80 | public void testIpv4Unicast() { |
| 81 | selector = DefaultTrafficSelector.builder() |
| 82 | .matchEthType(Ethernet.TYPE_IPV4) |
| 83 | .matchIPDst(IPV4_UNICAST_ADDR) |
| 84 | .build(); |
Charles Chan | 384aea2 | 2018-08-23 22:08:02 -0700 | [diff] [blame] | 85 | testFft(selector, ForwardingFunctionType.IPV4_ROUTING); |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | @Test |
| 89 | @Ignore |
| 90 | public void testIpv4Multicast() { |
| 91 | selector = DefaultTrafficSelector.builder() |
| 92 | .matchEthType(Ethernet.TYPE_IPV4) |
| 93 | .matchIPDst(IPV4_MCAST_ADDR) |
| 94 | .build(); |
Charles Chan | 384aea2 | 2018-08-23 22:08:02 -0700 | [diff] [blame] | 95 | testFft(selector, ForwardingFunctionType.IPV4_ROUTING); |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | @Test |
| 99 | @Ignore |
| 100 | public void testIpv6Unicast() { |
| 101 | selector = DefaultTrafficSelector.builder() |
| 102 | .matchEthType(Ethernet.TYPE_IPV6) |
| 103 | .matchIPDst(IPV6_UNICAST_ADDR) |
| 104 | .build(); |
Charles Chan | 384aea2 | 2018-08-23 22:08:02 -0700 | [diff] [blame] | 105 | testFft(selector, ForwardingFunctionType.IPV6_ROUTING); |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | @Test |
| 109 | @Ignore |
| 110 | public void testIpv6Multicast() { |
| 111 | selector = DefaultTrafficSelector.builder() |
| 112 | .matchEthType(Ethernet.TYPE_IPV6) |
| 113 | .matchIPDst(IPV6_MCAST_ADDR) |
| 114 | .build(); |
Charles Chan | 384aea2 | 2018-08-23 22:08:02 -0700 | [diff] [blame] | 115 | testFft(selector, ForwardingFunctionType.IPV4_ROUTING); |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | @Test |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 119 | public void testMplsUnicast() { |
| 120 | selector = DefaultTrafficSelector.builder() |
| 121 | .matchEthType(Ethernet.MPLS_UNICAST) |
| 122 | .matchMplsLabel(MPLS_10) |
| 123 | .matchMplsBos(true) |
| 124 | .build(); |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 125 | testFft(selector, ForwardingFunctionType.MPLS_SEGMENT_ROUTING); |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | private void testFft(TrafficSelector selector, ForwardingFunctionType expectedFft) { |
| 129 | ForwardingObjective fwd = DefaultForwardingObjective.builder() |
| 130 | .withSelector(selector) |
| 131 | .withFlag(ForwardingObjective.Flag.SPECIFIC) |
| 132 | .nextStep(0) |
| 133 | .fromApp(APP_ID) |
| 134 | .add(); |
| 135 | assertEquals(expectedFft, |
| 136 | ForwardingFunctionType.getForwardingFunctionType(fwd)); |
| 137 | } |
| 138 | } |