blob: e59086bd262c77680f29a92fb7d1f1dcdf360e1a [file] [log] [blame]
Yi Tsengfa4a1c72017-11-03 10:22:38 -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;
18
19import com.google.common.collect.ImmutableList;
20import org.junit.Before;
21import org.junit.Test;
22import org.onlab.packet.MacAddress;
Yi Tseng1b154bd2017-11-20 17:48:19 -080023import org.onlab.packet.MplsLabel;
Yi Tsengfa4a1c72017-11-03 10:22:38 -070024import org.onlab.packet.VlanId;
25import org.onlab.util.ImmutableByteSequence;
26import org.onosproject.net.PortNumber;
27import org.onosproject.net.flow.DefaultTrafficTreatment;
28import org.onosproject.net.flow.TrafficTreatment;
29import org.onosproject.net.pi.runtime.PiAction;
30import org.onosproject.net.pi.runtime.PiActionParam;
31
32import static org.junit.Assert.assertEquals;
33
34/**
35 * Test for fabric interpreter.
36 */
37public class FabricInterpreterTest {
38 private static final VlanId VLAN_100 = VlanId.vlanId("100");
39 private static final PortNumber PORT_1 = PortNumber.portNumber(1);
40 private static final MacAddress SRC_MAC = MacAddress.valueOf("00:00:00:00:00:01");
41 private static final MacAddress DST_MAC = MacAddress.valueOf("00:00:00:00:00:02");
Yi Tseng1b154bd2017-11-20 17:48:19 -080042 private static final MplsLabel MPLS_10 = MplsLabel.mplsLabel(10);
Yi Tsengfa4a1c72017-11-03 10:22:38 -070043
44 private FabricInterpreter interpreter;
45
46 @Before
47 public void setup() {
48 interpreter = new FabricInterpreter();
49 }
50
51 /* Filtering control block */
52
53 /**
54 * Map treatment to push_internal_vlan action.
55 */
56 @Test
Carmelo Casconeb5324e72018-11-25 02:26:32 -080057 public void testFilteringTreatmentPermitWithInternalVlan() throws Exception {
Yi Tsengfa4a1c72017-11-03 10:22:38 -070058 TrafficTreatment treatment = DefaultTrafficTreatment.builder()
59 .pushVlan()
60 .setVlanId(VLAN_100)
61 .build();
62 PiAction mappedAction = interpreter.mapTreatment(treatment,
Yi Tseng43ee7e82018-04-12 16:37:34 +080063 FabricConstants.FABRIC_INGRESS_FILTERING_INGRESS_PORT_VLAN);
Carmelo Casconeb5324e72018-11-25 02:26:32 -080064 PiActionParam param = new PiActionParam(FabricConstants.VLAN_ID,
Yi Tsengfa4a1c72017-11-03 10:22:38 -070065 ImmutableByteSequence.copyFrom(VLAN_100.toShort()));
66 PiAction expectedAction = PiAction.builder()
Carmelo Casconeb5324e72018-11-25 02:26:32 -080067 .withId(FabricConstants.FABRIC_INGRESS_FILTERING_PERMIT_WITH_INTERNAL_VLAN)
Yi Tsengfa4a1c72017-11-03 10:22:38 -070068 .withParameter(param)
69 .build();
70
71 assertEquals(expectedAction, mappedAction);
72 }
73
74 /**
Carmelo Casconeb5324e72018-11-25 02:26:32 -080075 * Map treatment to permit action.
Yi Tsengfa4a1c72017-11-03 10:22:38 -070076 */
77 @Test
Carmelo Casconeb5324e72018-11-25 02:26:32 -080078 public void testFilteringTreatmentPermit() throws Exception {
Yi Tsengfa4a1c72017-11-03 10:22:38 -070079 TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
80 PiAction mappedAction = interpreter.mapTreatment(treatment,
Yi Tseng43ee7e82018-04-12 16:37:34 +080081 FabricConstants.FABRIC_INGRESS_FILTERING_INGRESS_PORT_VLAN);
Yi Tsengfa4a1c72017-11-03 10:22:38 -070082 PiAction expectedAction = PiAction.builder()
Carmelo Casconeb5324e72018-11-25 02:26:32 -080083 .withId(FabricConstants.FABRIC_INGRESS_FILTERING_PERMIT)
Yi Tsengfa4a1c72017-11-03 10:22:38 -070084 .build();
85
86 assertEquals(expectedAction, mappedAction);
87 }
88
89 /* Forwarding control block */
90
91 /**
Carmelo Casconeb5324e72018-11-25 02:26:32 -080092 * Map empty treatment for routing v4 table.
Yi Tsengdf3eec52018-02-15 14:56:02 -080093 */
94 @Test
Carmelo Casconeb5324e72018-11-25 02:26:32 -080095 public void testRoutingV4TreatmentEmpty() throws Exception {
Yi Tsengdf3eec52018-02-15 14:56:02 -080096 TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
Carmelo Casconeb5324e72018-11-25 02:26:32 -080097 PiAction mappedAction = interpreter.mapTreatment(
98 treatment, FabricConstants.FABRIC_INGRESS_FORWARDING_ROUTING_V4);
Charles Chancf696e52018-08-16 16:25:13 -070099 PiAction expectedAction = PiAction.builder()
Charles Chancd03f072018-08-31 17:46:37 -0700100 .withId(FabricConstants.FABRIC_INGRESS_FORWARDING_NOP_ROUTING_V4)
Charles Chancf696e52018-08-16 16:25:13 -0700101 .build();
102 assertEquals(expectedAction, mappedAction);
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800103 }
Charles Chancf696e52018-08-16 16:25:13 -0700104
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800105 /**
106 * Map empty treatment for ACL table.
107 */
108 @Test
109 public void testAclTreatmentEmpty() throws Exception {
110 TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
111 PiAction mappedAction = interpreter.mapTreatment(
112 treatment, FabricConstants.FABRIC_INGRESS_ACL_ACL);
113 PiAction expectedAction = PiAction.builder()
114 .withId(FabricConstants.FABRIC_INGRESS_ACL_NOP_ACL)
Charles Chancf696e52018-08-16 16:25:13 -0700115 .build();
116 assertEquals(expectedAction, mappedAction);
Yi Tsengdf3eec52018-02-15 14:56:02 -0800117 }
118
Yi Tsengfa4a1c72017-11-03 10:22:38 -0700119 /* Next control block */
120
121 /**
122 * Map treatment to output action.
123 */
124 @Test
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800125 public void testNextTreatmentSimpleOutput() throws Exception {
Yi Tsengfa4a1c72017-11-03 10:22:38 -0700126 TrafficTreatment treatment = DefaultTrafficTreatment.builder()
127 .setOutput(PORT_1)
128 .build();
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800129 PiAction mappedAction = interpreter.mapTreatment(
130 treatment, FabricConstants.FABRIC_INGRESS_NEXT_SIMPLE);
131 PiActionParam param = new PiActionParam(FabricConstants.PORT_NUM, PORT_1.toLong());
Yi Tsengfa4a1c72017-11-03 10:22:38 -0700132 PiAction expectedAction = PiAction.builder()
Yi Tseng47eac892018-07-11 02:17:04 +0800133 .withId(FabricConstants.FABRIC_INGRESS_NEXT_OUTPUT_SIMPLE)
Yi Tsengfa4a1c72017-11-03 10:22:38 -0700134 .withParameter(param)
135 .build();
Yi Tsengfa4a1c72017-11-03 10:22:38 -0700136 assertEquals(expectedAction, mappedAction);
137 }
138
139 /**
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800140 * Map treatment for hashed table to routing v4 action.
Yi Tsengfa4a1c72017-11-03 10:22:38 -0700141 */
142 @Test
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800143 public void testNextTreatmentHashedRoutingV4() throws Exception {
Yi Tsengfa4a1c72017-11-03 10:22:38 -0700144 TrafficTreatment treatment = DefaultTrafficTreatment.builder()
145 .setEthSrc(SRC_MAC)
146 .setEthDst(DST_MAC)
147 .setOutput(PORT_1)
148 .build();
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800149 PiAction mappedAction = interpreter.mapTreatment(
150 treatment, FabricConstants.FABRIC_INGRESS_NEXT_HASHED);
151 PiActionParam ethSrcParam = new PiActionParam(FabricConstants.SMAC, SRC_MAC.toBytes());
152 PiActionParam ethDstParam = new PiActionParam(FabricConstants.DMAC, DST_MAC.toBytes());
153 PiActionParam portParam = new PiActionParam(FabricConstants.PORT_NUM, PORT_1.toLong());
Yi Tsengfa4a1c72017-11-03 10:22:38 -0700154 PiAction expectedAction = PiAction.builder()
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800155 .withId(FabricConstants.FABRIC_INGRESS_NEXT_ROUTING_HASHED)
Yi Tsengfa4a1c72017-11-03 10:22:38 -0700156 .withParameters(ImmutableList.of(ethSrcParam, ethDstParam, portParam))
157 .build();
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800158 assertEquals(expectedAction, mappedAction);
159 }
Yi Tsengfa4a1c72017-11-03 10:22:38 -0700160
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800161 /**
162 * Map treatment for hashed table to routing v4 action.
163 */
164 @Test
165 public void testNextTreatmentHashedRoutingMpls() throws Exception {
166 TrafficTreatment treatment = DefaultTrafficTreatment.builder()
167 .setEthSrc(SRC_MAC)
168 .setEthDst(DST_MAC)
169 .setOutput(PORT_1)
170 .pushMpls()
171 .setMpls(MPLS_10)
172 .build();
173 PiAction mappedAction = interpreter.mapTreatment(
174 treatment, FabricConstants.FABRIC_INGRESS_NEXT_HASHED);
175 PiActionParam ethSrcParam = new PiActionParam(FabricConstants.SMAC, SRC_MAC.toBytes());
176 PiActionParam ethDstParam = new PiActionParam(FabricConstants.DMAC, DST_MAC.toBytes());
177 PiActionParam portParam = new PiActionParam(FabricConstants.PORT_NUM, PORT_1.toLong());
178 PiActionParam mplsParam = new PiActionParam(FabricConstants.LABEL, MPLS_10.toInt());
179 PiAction expectedAction = PiAction.builder()
180 .withId(FabricConstants.FABRIC_INGRESS_NEXT_MPLS_ROUTING_HASHED)
181 .withParameters(ImmutableList.of(ethSrcParam, ethDstParam, portParam, mplsParam))
182 .build();
Yi Tsengfa4a1c72017-11-03 10:22:38 -0700183 assertEquals(expectedAction, mappedAction);
184 }
185
186 /**
187 * Map treatment to set_vlan_output action.
188 */
189 @Test
190 public void testNextTreatment3() throws Exception {
191 TrafficTreatment treatment = DefaultTrafficTreatment.builder()
192 .setVlanId(VLAN_100)
Yi Tsengfa4a1c72017-11-03 10:22:38 -0700193 .build();
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800194 PiAction mappedAction = interpreter.mapTreatment(
195 treatment, FabricConstants.FABRIC_INGRESS_NEXT_NEXT_VLAN);
196 PiActionParam vlanParam = new PiActionParam(
197 FabricConstants.VLAN_ID, VLAN_100.toShort());
Yi Tsengfa4a1c72017-11-03 10:22:38 -0700198 PiAction expectedAction = PiAction.builder()
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800199 .withId(FabricConstants.FABRIC_INGRESS_NEXT_SET_VLAN)
200 .withParameter(vlanParam)
Yi Tseng1b154bd2017-11-20 17:48:19 -0800201 .build();
202 assertEquals(expectedAction, mappedAction);
203 }
Yi Tsengfa4a1c72017-11-03 10:22:38 -0700204}