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 | |
| 17 | package org.onosproject.pipelines.fabric.pipeliner; |
| 18 | |
| 19 | import org.junit.Before; |
Carmelo Cascone | 4164436 | 2018-08-09 16:56:43 -0700 | [diff] [blame] | 20 | import org.junit.Test; |
Yi Tseng | 4fd2843 | 2018-02-01 14:48:03 -0800 | [diff] [blame] | 21 | import org.onlab.junit.TestUtils; |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 22 | import org.onlab.osgi.ServiceDirectory; |
| 23 | import org.onlab.packet.IpPrefix; |
| 24 | import org.onlab.packet.MacAddress; |
| 25 | import org.onlab.packet.MplsLabel; |
| 26 | import org.onlab.packet.VlanId; |
| 27 | import org.onosproject.TestApplicationId; |
| 28 | import org.onosproject.core.ApplicationId; |
| 29 | import org.onosproject.net.DeviceId; |
| 30 | import org.onosproject.net.PortNumber; |
| 31 | import org.onosproject.net.behaviour.PipelinerContext; |
Yi Tseng | 4fd2843 | 2018-02-01 14:48:03 -0800 | [diff] [blame] | 32 | import org.onosproject.net.driver.Driver; |
| 33 | import org.onosproject.net.driver.DriverHandler; |
Yi Tseng | 20f9e7b | 2018-05-24 23:27:39 +0800 | [diff] [blame] | 34 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 35 | import org.onosproject.net.flow.TrafficSelector; |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 36 | import org.onosproject.net.flow.criteria.PiCriterion; |
Yi Tseng | f78e174 | 2018-04-08 19:57:17 +0800 | [diff] [blame] | 37 | import org.onosproject.net.group.GroupService; |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 38 | import org.onosproject.pipelines.fabric.FabricConstants; |
Yi Tseng | 1b154bd | 2017-11-20 17:48:19 -0800 | [diff] [blame] | 39 | import org.onosproject.pipelines.fabric.FabricInterpreter; |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 40 | |
| 41 | import static org.easymock.EasyMock.createNiceMock; |
| 42 | import static org.easymock.EasyMock.expect; |
| 43 | import static org.easymock.EasyMock.replay; |
| 44 | |
Carmelo Cascone | 4164436 | 2018-08-09 16:56:43 -0700 | [diff] [blame] | 45 | public class FabricPipelinerTest { |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 46 | static final ApplicationId APP_ID = TestApplicationId.create("FabricPipelinerTest"); |
| 47 | static final DeviceId DEVICE_ID = DeviceId.deviceId("device:bmv2:11"); |
| 48 | static final int PRIORITY = 100; |
| 49 | static final PortNumber PORT_1 = PortNumber.portNumber(1); |
Yi Tseng | 1b154bd | 2017-11-20 17:48:19 -0800 | [diff] [blame] | 50 | static final PortNumber PORT_2 = PortNumber.portNumber(2); |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 51 | static final VlanId VLAN_100 = VlanId.vlanId("100"); |
| 52 | static final MacAddress HOST_MAC = MacAddress.valueOf("00:00:00:00:00:01"); |
| 53 | static final MacAddress ROUTER_MAC = MacAddress.valueOf("00:00:00:00:02:01"); |
| 54 | static final IpPrefix IPV4_UNICAST_ADDR = IpPrefix.valueOf("10.0.0.1/32"); |
| 55 | static final IpPrefix IPV4_MCAST_ADDR = IpPrefix.valueOf("224.0.0.1/32"); |
| 56 | static final IpPrefix IPV6_UNICAST_ADDR = IpPrefix.valueOf("2000::1/32"); |
| 57 | static final IpPrefix IPV6_MCAST_ADDR = IpPrefix.valueOf("ff00::1/32"); |
| 58 | static final MplsLabel MPLS_10 = MplsLabel.mplsLabel(10); |
| 59 | static final Integer NEXT_ID_1 = 1; |
Yi Tseng | 20f9e7b | 2018-05-24 23:27:39 +0800 | [diff] [blame] | 60 | static final TrafficSelector VLAN_META = DefaultTrafficSelector.builder() |
| 61 | .matchVlanId(VLAN_100) |
| 62 | .build(); |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 63 | |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 64 | static final PiCriterion VLAN_VALID = PiCriterion.builder() |
Yi Tseng | 43ee7e8 | 2018-04-12 16:37:34 +0800 | [diff] [blame] | 65 | .matchExact(FabricConstants.HDR_VLAN_TAG_IS_VALID, new byte[]{1}) |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 66 | .build(); |
| 67 | static final PiCriterion VLAN_INVALID = PiCriterion.builder() |
Yi Tseng | 43ee7e8 | 2018-04-12 16:37:34 +0800 | [diff] [blame] | 68 | .matchExact(FabricConstants.HDR_VLAN_TAG_IS_VALID, new byte[]{0}) |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 69 | .build(); |
| 70 | |
| 71 | FabricPipeliner pipeliner; |
Yi Tseng | 1b154bd | 2017-11-20 17:48:19 -0800 | [diff] [blame] | 72 | FabricInterpreter interpreter; |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 73 | |
| 74 | @Before |
| 75 | public void setup() { |
| 76 | pipeliner = new FabricPipeliner(); |
| 77 | |
Yi Tseng | f78e174 | 2018-04-08 19:57:17 +0800 | [diff] [blame] | 78 | GroupService mockGroupService = createNiceMock(GroupService.class); |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 79 | ServiceDirectory serviceDirectory = createNiceMock(ServiceDirectory.class); |
| 80 | PipelinerContext pipelinerContext = createNiceMock(PipelinerContext.class); |
Yi Tseng | 4fd2843 | 2018-02-01 14:48:03 -0800 | [diff] [blame] | 81 | DriverHandler driverHandler = createNiceMock(DriverHandler.class); |
| 82 | Driver mockDriver = createNiceMock(Driver.class); |
| 83 | expect(mockDriver.getProperty("supportTableCounters")).andReturn("true").anyTimes(); |
| 84 | expect(mockDriver.getProperty("noHashedTable")).andReturn("false").anyTimes(); |
| 85 | expect(driverHandler.driver()).andReturn(mockDriver).anyTimes(); |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 86 | expect(pipelinerContext.directory()).andReturn(serviceDirectory).anyTimes(); |
Yi Tseng | f78e174 | 2018-04-08 19:57:17 +0800 | [diff] [blame] | 87 | expect(serviceDirectory.get(GroupService.class)).andReturn(mockGroupService).anyTimes(); |
Yi Tseng | 4fd2843 | 2018-02-01 14:48:03 -0800 | [diff] [blame] | 88 | replay(serviceDirectory, pipelinerContext, driverHandler, mockDriver); |
| 89 | TestUtils.setField(pipeliner, "handler", driverHandler); |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 90 | |
| 91 | pipeliner.init(DEVICE_ID, pipelinerContext); |
Yi Tseng | 1b154bd | 2017-11-20 17:48:19 -0800 | [diff] [blame] | 92 | interpreter = new FabricInterpreter(); |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 93 | } |
Carmelo Cascone | 4164436 | 2018-08-09 16:56:43 -0700 | [diff] [blame] | 94 | |
| 95 | @Test |
| 96 | public void fakeTest() { |
| 97 | // Needed otherwise Bazel complains about a test class without test cases. |
| 98 | assert true; |
| 99 | } |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 100 | } |