blob: c3613770db682965fc54d5e76aff773b421d620b [file] [log] [blame]
Yi Tseng0b809722017-11-03 10:23:26 -07001/*
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
17package org.onosproject.pipelines.fabric.pipeliner;
18
19import org.junit.Before;
Carmelo Cascone41644362018-08-09 16:56:43 -070020import org.junit.Test;
Yi Tseng4fd28432018-02-01 14:48:03 -080021import org.onlab.junit.TestUtils;
Yi Tseng0b809722017-11-03 10:23:26 -070022import org.onlab.osgi.ServiceDirectory;
23import org.onlab.packet.IpPrefix;
24import org.onlab.packet.MacAddress;
25import org.onlab.packet.MplsLabel;
26import org.onlab.packet.VlanId;
27import org.onosproject.TestApplicationId;
28import org.onosproject.core.ApplicationId;
29import org.onosproject.net.DeviceId;
30import org.onosproject.net.PortNumber;
31import org.onosproject.net.behaviour.PipelinerContext;
Yi Tseng4fd28432018-02-01 14:48:03 -080032import org.onosproject.net.driver.Driver;
33import org.onosproject.net.driver.DriverHandler;
Yi Tseng20f9e7b2018-05-24 23:27:39 +080034import org.onosproject.net.flow.DefaultTrafficSelector;
35import org.onosproject.net.flow.TrafficSelector;
Yi Tseng0b809722017-11-03 10:23:26 -070036import org.onosproject.net.flow.criteria.PiCriterion;
Yi Tsengf78e1742018-04-08 19:57:17 +080037import org.onosproject.net.group.GroupService;
Yi Tseng0b809722017-11-03 10:23:26 -070038import org.onosproject.pipelines.fabric.FabricConstants;
Yi Tseng1b154bd2017-11-20 17:48:19 -080039import org.onosproject.pipelines.fabric.FabricInterpreter;
Yi Tseng0b809722017-11-03 10:23:26 -070040
41import static org.easymock.EasyMock.createNiceMock;
42import static org.easymock.EasyMock.expect;
43import static org.easymock.EasyMock.replay;
44
Carmelo Cascone41644362018-08-09 16:56:43 -070045public class FabricPipelinerTest {
Yi Tseng0b809722017-11-03 10:23:26 -070046 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 Tseng1b154bd2017-11-20 17:48:19 -080050 static final PortNumber PORT_2 = PortNumber.portNumber(2);
Yi Tseng0b809722017-11-03 10:23:26 -070051 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 Tseng20f9e7b2018-05-24 23:27:39 +080060 static final TrafficSelector VLAN_META = DefaultTrafficSelector.builder()
61 .matchVlanId(VLAN_100)
62 .build();
Yi Tseng0b809722017-11-03 10:23:26 -070063
Yi Tseng0b809722017-11-03 10:23:26 -070064 static final PiCriterion VLAN_VALID = PiCriterion.builder()
Yi Tseng43ee7e82018-04-12 16:37:34 +080065 .matchExact(FabricConstants.HDR_VLAN_TAG_IS_VALID, new byte[]{1})
Yi Tseng0b809722017-11-03 10:23:26 -070066 .build();
67 static final PiCriterion VLAN_INVALID = PiCriterion.builder()
Yi Tseng43ee7e82018-04-12 16:37:34 +080068 .matchExact(FabricConstants.HDR_VLAN_TAG_IS_VALID, new byte[]{0})
Yi Tseng0b809722017-11-03 10:23:26 -070069 .build();
70
71 FabricPipeliner pipeliner;
Yi Tseng1b154bd2017-11-20 17:48:19 -080072 FabricInterpreter interpreter;
Yi Tseng0b809722017-11-03 10:23:26 -070073
74 @Before
75 public void setup() {
76 pipeliner = new FabricPipeliner();
77
Yi Tsengf78e1742018-04-08 19:57:17 +080078 GroupService mockGroupService = createNiceMock(GroupService.class);
Yi Tseng0b809722017-11-03 10:23:26 -070079 ServiceDirectory serviceDirectory = createNiceMock(ServiceDirectory.class);
80 PipelinerContext pipelinerContext = createNiceMock(PipelinerContext.class);
Yi Tseng4fd28432018-02-01 14:48:03 -080081 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 Tseng0b809722017-11-03 10:23:26 -070086 expect(pipelinerContext.directory()).andReturn(serviceDirectory).anyTimes();
Yi Tsengf78e1742018-04-08 19:57:17 +080087 expect(serviceDirectory.get(GroupService.class)).andReturn(mockGroupService).anyTimes();
Yi Tseng4fd28432018-02-01 14:48:03 -080088 replay(serviceDirectory, pipelinerContext, driverHandler, mockDriver);
89 TestUtils.setField(pipeliner, "handler", driverHandler);
Yi Tseng0b809722017-11-03 10:23:26 -070090
91 pipeliner.init(DEVICE_ID, pipelinerContext);
Yi Tseng1b154bd2017-11-20 17:48:19 -080092 interpreter = new FabricInterpreter();
Yi Tseng0b809722017-11-03 10:23:26 -070093 }
Carmelo Cascone41644362018-08-09 16:56:43 -070094
95 @Test
96 public void fakeTest() {
97 // Needed otherwise Bazel complains about a test class without test cases.
98 assert true;
99 }
Yi Tseng0b809722017-11-03 10:23:26 -0700100}