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