blob: ec125537a0b545e4cb15d52b92dead535987c01b [file] [log] [blame]
Bharat Saraswal0fa12e92015-12-04 02:58:01 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Bharat Saraswal0fa12e92015-12-04 02:58:01 +05303 *
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 */
16package org.onosproject.sfc.installer.impl;
17
Phaneendra Manda0f21ad62016-02-12 19:32:13 +053018import static com.google.common.base.Preconditions.checkNotNull;
19import static org.onosproject.net.flow.instructions.ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI;
20import static org.onosproject.net.flow.instructions.ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI;
21import static org.slf4j.LoggerFactory.getLogger;
22
23import java.util.LinkedList;
24import java.util.List;
25import java.util.ListIterator;
26
Bharat Saraswal0fa12e92015-12-04 02:58:01 +053027import org.onlab.osgi.DefaultServiceDirectory;
28import org.onlab.osgi.ServiceDirectory;
Mahesh Poojary S96cdcd22015-12-10 11:01:30 +053029import org.onlab.packet.Ethernet;
Phaneendra Manda0f21ad62016-02-12 19:32:13 +053030import org.onlab.packet.IPv4;
31import org.onlab.packet.IpPrefix;
Bharat Saraswal0fa12e92015-12-04 02:58:01 +053032import org.onlab.packet.MacAddress;
33import org.onlab.packet.TpPort;
34import org.onlab.packet.VlanId;
35import org.onosproject.core.ApplicationId;
Phaneendra Manda0f21ad62016-02-12 19:32:13 +053036import org.onosproject.net.ConnectPoint;
Bharat Saraswal0fa12e92015-12-04 02:58:01 +053037import org.onosproject.net.DeviceId;
Mahesh Poojary S96cdcd22015-12-10 11:01:30 +053038import org.onosproject.net.Host;
39import org.onosproject.net.HostId;
Phaneendra Manda0f21ad62016-02-12 19:32:13 +053040import org.onosproject.net.NshServiceIndex;
Bharat Saraswal0fa12e92015-12-04 02:58:01 +053041import org.onosproject.net.NshServicePathId;
Mahesh Poojary S96cdcd22015-12-10 11:01:30 +053042import org.onosproject.net.PortNumber;
Bharat Saraswal0fa12e92015-12-04 02:58:01 +053043import org.onosproject.net.behaviour.ExtensionTreatmentResolver;
Jonathan Hart51539b82015-10-29 09:53:04 -070044import org.onosproject.net.device.DeviceService;
Bharat Saraswal0fa12e92015-12-04 02:58:01 +053045import org.onosproject.net.driver.DriverHandler;
46import org.onosproject.net.driver.DriverService;
47import org.onosproject.net.flow.DefaultTrafficSelector;
48import org.onosproject.net.flow.DefaultTrafficTreatment;
49import org.onosproject.net.flow.TrafficSelector;
50import org.onosproject.net.flow.TrafficTreatment;
51import org.onosproject.net.flow.criteria.Criteria;
52import org.onosproject.net.flow.instructions.ExtensionTreatment;
53import org.onosproject.net.flowobjective.DefaultForwardingObjective;
54import org.onosproject.net.flowobjective.FlowObjectiveService;
55import org.onosproject.net.flowobjective.ForwardingObjective;
56import org.onosproject.net.flowobjective.ForwardingObjective.Flag;
57import org.onosproject.net.flowobjective.Objective;
Mahesh Poojary S96cdcd22015-12-10 11:01:30 +053058import org.onosproject.net.host.HostService;
Bharat Saraswal0fa12e92015-12-04 02:58:01 +053059import org.onosproject.sfc.installer.FlowClassifierInstallerService;
Phaneendra Manda0f21ad62016-02-12 19:32:13 +053060import org.onosproject.vtnrsc.FiveTuple;
Bharat Saraswal0fa12e92015-12-04 02:58:01 +053061import org.onosproject.vtnrsc.FlowClassifier;
62import org.onosproject.vtnrsc.FlowClassifierId;
63import org.onosproject.vtnrsc.PortChain;
64import org.onosproject.vtnrsc.PortPair;
65import org.onosproject.vtnrsc.PortPairGroup;
66import org.onosproject.vtnrsc.PortPairGroupId;
67import org.onosproject.vtnrsc.PortPairId;
68import org.onosproject.vtnrsc.VirtualPortId;
69import org.onosproject.vtnrsc.flowclassifier.FlowClassifierService;
70import org.onosproject.vtnrsc.portpair.PortPairService;
71import org.onosproject.vtnrsc.portpairgroup.PortPairGroupService;
72import org.onosproject.vtnrsc.service.VtnRscService;
73import org.onosproject.vtnrsc.virtualport.VirtualPortService;
74import org.slf4j.Logger;
75
76/**
77 * Provides flow classifier installer implementation.
78 */
79public class FlowClassifierInstallerImpl implements FlowClassifierInstallerService {
Bharat Saraswal0fa12e92015-12-04 02:58:01 +053080 private final Logger log = getLogger(getClass());
81
Bharat Saraswal0fa12e92015-12-04 02:58:01 +053082 protected VirtualPortService virtualPortService;
Bharat Saraswal0fa12e92015-12-04 02:58:01 +053083 protected VtnRscService vtnRscService;
Bharat Saraswal0fa12e92015-12-04 02:58:01 +053084 protected PortPairService portPairService;
Bharat Saraswal0fa12e92015-12-04 02:58:01 +053085 protected PortPairGroupService portPairGroupService;
Bharat Saraswal0fa12e92015-12-04 02:58:01 +053086 protected FlowClassifierService flowClassifierService;
Bharat Saraswal0fa12e92015-12-04 02:58:01 +053087 protected DriverService driverService;
Mahesh Poojary S96cdcd22015-12-10 11:01:30 +053088 protected DeviceService deviceService;
Mahesh Poojary S96cdcd22015-12-10 11:01:30 +053089 protected HostService hostService;
Bharat Saraswal0fa12e92015-12-04 02:58:01 +053090 protected FlowObjectiveService flowObjectiveService;
91 protected ApplicationId appId;
92
93 private static final String DRIVER_NAME = "onosfw";
94 private static final String FLOW_CLASSIFIER_NOT_NULL = "Flow-Classifier cannot be null";
95 private static final String FLOW_CLASSIFIER_ID_NOT_NULL = "Flow-Classifier-Id cannot be null";
96 private static final String PORT_CHAIN_NOT_NULL = "Port-Chain cannot be null";
97 private static final int NULL = 0;
Phaneendra Manda0f21ad62016-02-12 19:32:13 +053098 private static final int FLOW_CLASSIFIER_PRIORITY = 0x7fff;
99 private static final short NSH_SI_ID = 0xff;
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530100
101 /**
102 * Default constructor.
103 */
104 public FlowClassifierInstallerImpl() {
105 }
106
107 /**
108 * Explicit constructor.
109 *
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530110 * @param appId application id.
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530111 */
112 public FlowClassifierInstallerImpl(ApplicationId appId) {
113 this.appId = checkNotNull(appId, "ApplicationId can not be null");
114 ServiceDirectory serviceDirectory = new DefaultServiceDirectory();
115 this.flowObjectiveService = serviceDirectory.get(FlowObjectiveService.class);
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530116 this.driverService = serviceDirectory.get(DriverService.class);
117 this.deviceService = serviceDirectory.get(DeviceService.class);
118 this.hostService = serviceDirectory.get(HostService.class);
119 this.virtualPortService = serviceDirectory.get(VirtualPortService.class);
120 this.vtnRscService = serviceDirectory.get(VtnRscService.class);
121 this.portPairService = serviceDirectory.get(PortPairService.class);
122 this.portPairGroupService = serviceDirectory.get(PortPairGroupService.class);
123 this.flowClassifierService = serviceDirectory.get(FlowClassifierService.class);
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530124 }
125
126 @Override
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530127 public ConnectPoint installFlowClassifier(PortChain portChain, NshServicePathId nshSpiId) {
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530128 checkNotNull(portChain, PORT_CHAIN_NOT_NULL);
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530129 // Get the portPairGroup
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530130 List<PortPairGroupId> llPortPairGroupIdList = portChain.portPairGroups();
131 ListIterator<PortPairGroupId> portPairGroupIdListIterator = llPortPairGroupIdList.listIterator();
132 PortPairGroupId portPairGroupId = portPairGroupIdListIterator.next();
133 PortPairGroup portPairGroup = portPairGroupService.getPortPairGroup(portPairGroupId);
134 List<PortPairId> llPortPairIdList = portPairGroup.portPairs();
135
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530136 // Get port pair
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530137 ListIterator<PortPairId> portPairListIterator = llPortPairIdList.listIterator();
138 PortPairId portPairId = portPairListIterator.next();
139 PortPair portPair = portPairService.getPortPair(portPairId);
140
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530141 return processFlowClassifier(portChain, portPair, nshSpiId, null, Objective.Operation.ADD);
142 }
143
144 @Override
145 public ConnectPoint unInstallFlowClassifier(PortChain portChain, NshServicePathId nshSpiId) {
146 checkNotNull(portChain, PORT_CHAIN_NOT_NULL);
147 // Get the portPairGroup
148 List<PortPairGroupId> llPortPairGroupIdList = portChain.portPairGroups();
149 ListIterator<PortPairGroupId> portPairGroupIdListIterator = llPortPairGroupIdList.listIterator();
150 PortPairGroupId portPairGroupId = portPairGroupIdListIterator.next();
151 PortPairGroup portPairGroup = portPairGroupService.getPortPairGroup(portPairGroupId);
152 List<PortPairId> llPortPairIdList = portPairGroup.portPairs();
153
154 // Get port pair
155 ListIterator<PortPairId> portPairListIterator = llPortPairIdList.listIterator();
156 PortPairId portPairId = portPairListIterator.next();
157 PortPair portPair = portPairService.getPortPair(portPairId);
158
159 return processFlowClassifier(portChain, portPair, nshSpiId, null, Objective.Operation.REMOVE);
160 }
161
162 @Override
163 public ConnectPoint installLoadBalancedFlowClassifier(PortChain portChain, FiveTuple fiveTuple,
164 NshServicePathId nshSpiId) {
165 checkNotNull(portChain, PORT_CHAIN_NOT_NULL);
166
167 // Get the load balanced path
168 List<PortPairId> portPairs = portChain.getLoadBalancePath(fiveTuple);
169
170 // Get the first port pair
171 ListIterator<PortPairId> portPairListIterator = portPairs.listIterator();
172 PortPairId portPairId = portPairListIterator.next();
173 PortPair portPair = portPairService.getPortPair(portPairId);
174
175 return processFlowClassifier(portChain, portPair, nshSpiId, fiveTuple, Objective.Operation.ADD);
176 }
177
178 @Override
179 public ConnectPoint unInstallLoadBalancedFlowClassifier(PortChain portChain, FiveTuple fiveTuple,
180 NshServicePathId nshSpiId) {
181 checkNotNull(portChain, PORT_CHAIN_NOT_NULL);
182 // Get the load balanced path
183 List<PortPairId> portPairs = portChain.getLoadBalancePath(fiveTuple);
184
185 // Get the first port pair
186 ListIterator<PortPairId> portPairListIterator = portPairs.listIterator();
187 PortPairId portPairId = portPairListIterator.next();
188 PortPair portPair = portPairService.getPortPair(portPairId);
189
190 return processFlowClassifier(portChain, portPair, nshSpiId, fiveTuple, Objective.Operation.REMOVE);
191 }
192
193 public ConnectPoint processFlowClassifier(PortChain portChain, PortPair portPair, NshServicePathId nshSpiId,
194 FiveTuple fiveTuple, Objective.Operation type) {
195
196 DeviceId deviceIdfromPortPair = vtnRscService.getSfToSffMaping(VirtualPortId.portId(portPair.ingress()));
197 MacAddress srcMacAddress = virtualPortService.getPort(VirtualPortId.portId(portPair.ingress())).macAddress();
198 Host host = hostService.getHost(HostId.hostId(srcMacAddress));
199 PortNumber port = host.location().port();
200
201 DeviceId deviceId = deviceIdfromPortPair;
202
203 // Vxlan tunnel port for NSH header(Vxlan + NSH).
204 TpPort nshDstPort = TpPort.tpPort(6633);
205
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530206 FlowClassifierInstallerService flowclassifierinstallerService;
207 // get flow classifiers
208 List<FlowClassifierId> llFlowClassifierList = portChain.flowClassifiers();
209 ListIterator<FlowClassifierId> flowClassifierListIterator = llFlowClassifierList.listIterator();
210
211 while (flowClassifierListIterator.hasNext()) {
212 FlowClassifierId flowclassifierId = flowClassifierListIterator.next();
213 FlowClassifier flowClassifier = flowClassifierService.getFlowClassifier(flowclassifierId);
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530214
215 if ((flowClassifier.srcPort() != null) && (!flowClassifier.srcPort().portId().isEmpty())) {
216 deviceId = vtnRscService.getSfToSffMaping(flowClassifier.srcPort());
217 }
218
219 // Build Traffic selector.
220 TrafficSelector.Builder selector = packTrafficSelector(flowClassifier, fiveTuple);
221
222 if (fiveTuple == null) {
223 // Send the packet to controller
224 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
225 treatment.setOutput(PortNumber.CONTROLLER);
Phaneendra Manda299877f2016-04-13 23:28:03 +0530226 sendServiceFunctionClassifier(selector, treatment, deviceId, type, flowClassifier.priority());
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530227 } else if (deviceId.equals(deviceIdfromPortPair)) {
228 // classifier and source device are in the same OVS. So directly send packet to first port pair
229 TrafficTreatment.Builder treatment = packTrafficTreatment(deviceId, port, nshDstPort,
230 nshSpiId, flowClassifier, true);
231 // Build forwarding objective and send to OVS.
Phaneendra Manda299877f2016-04-13 23:28:03 +0530232 sendServiceFunctionClassifier(selector, treatment, deviceId, type, flowClassifier.priority());
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530233 } else {
234 // classifier and source device are not in the same OVS. Send packet on vlan Tunnel
235 TrafficTreatment.Builder treatment = packTrafficTreatment(deviceId, port, nshDstPort,
236 nshSpiId, flowClassifier, false);
237 // Build forwarding objective and send to OVS.
Phaneendra Manda299877f2016-04-13 23:28:03 +0530238 sendServiceFunctionClassifier(selector, treatment, deviceId, type, flowClassifier.priority());
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530239
240 // At the other device get the packet from vlan and send to first port pair
241 TrafficSelector.Builder selectorDst = DefaultTrafficSelector.builder();
242 selectorDst.matchVlanId((VlanId.vlanId(Short.parseShort((vtnRscService
243 .getL3vni(flowClassifier.tenantId()).toString())))));
244 TrafficTreatment.Builder treatmentDst = DefaultTrafficTreatment.builder();
245 Host hostDst = hostService.getHost(HostId.hostId(srcMacAddress));
246 treatmentDst.setOutput(hostDst.location().port());
Phaneendra Manda299877f2016-04-13 23:28:03 +0530247 sendServiceFunctionClassifier(selectorDst, treatmentDst, deviceIdfromPortPair, type,
248 flowClassifier.priority());
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530249 }
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530250 }
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530251 return host.location();
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530252 }
253
254 /**
255 * Pack Traffic selector.
256 *
257 * @param flowClassifier flow-classifier
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530258 * @param fiveTuple five tuple info for the packet
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530259 * @return traffic selector
260 */
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530261 public TrafficSelector.Builder packTrafficSelector(FlowClassifier flowClassifier, FiveTuple fiveTuple) {
262
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530263 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
264
Mahesh Poojary S96cdcd22015-12-10 11:01:30 +0530265 if ((flowClassifier.srcIpPrefix() != null) && (flowClassifier.srcIpPrefix().prefixLength() != 0)) {
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530266 selector.matchIPSrc(flowClassifier.srcIpPrefix());
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530267 } else if (fiveTuple != null && fiveTuple.ipSrc() != null) {
268 selector.matchIPSrc(IpPrefix.valueOf(fiveTuple.ipSrc(), 24));
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530269 }
Mahesh Poojary S96cdcd22015-12-10 11:01:30 +0530270
271 if ((flowClassifier.dstIpPrefix() != null) && (flowClassifier.dstIpPrefix().prefixLength() != 0)) {
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530272 selector.matchIPDst(flowClassifier.dstIpPrefix());
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530273 } else if (fiveTuple != null && fiveTuple.ipDst() != null) {
274 selector.matchIPDst(IpPrefix.valueOf(fiveTuple.ipDst(), 24));
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530275 }
276
Mahesh Poojary S96cdcd22015-12-10 11:01:30 +0530277 if ((flowClassifier.protocol() != null) && (!flowClassifier.protocol().isEmpty())) {
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530278 if (flowClassifier.protocol().equalsIgnoreCase("TCP")) {
279 selector.add(Criteria.matchIPProtocol(IPv4.PROTOCOL_TCP));
280 } else if (flowClassifier.protocol().equalsIgnoreCase("UDP")) {
281 selector.add(Criteria.matchIPProtocol(IPv4.PROTOCOL_UDP));
282 }
283 } else if (fiveTuple != null && fiveTuple.protocol() != 0) {
284 selector.add(Criteria.matchIPProtocol(fiveTuple.protocol()));
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530285 }
Mahesh Poojary S96cdcd22015-12-10 11:01:30 +0530286
287 if (((flowClassifier.etherType() != null) && (!flowClassifier.etherType().isEmpty()))
288 && (flowClassifier.etherType().equals("IPv4") || flowClassifier.etherType().equals("IPv6"))) {
289 if (flowClassifier.etherType().equals("IPv4")) {
290 selector.matchEthType(Ethernet.TYPE_IPV4);
291 } else {
292 selector.matchEthType(Ethernet.TYPE_IPV6);
293 }
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530294 }
295
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530296 if ((flowClassifier.srcPort() != null) && (!flowClassifier.srcPort().portId().isEmpty())) {
297 VirtualPortId vPortId = VirtualPortId.portId(flowClassifier.srcPort().portId());
298 MacAddress macAddress = virtualPortService.getPort(vPortId).macAddress();
299 Host host = hostService.getHost(HostId.hostId(macAddress));
300 selector.matchInPort(host.location().port());
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530301 }
302
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530303 // Take the port information from five tuple only when the protocol is TCP.
304 if (fiveTuple != null && fiveTuple.protocol() == IPv4.PROTOCOL_TCP) {
305 selector.matchTcpSrc(TpPort.tpPort((int) fiveTuple.portSrc().toLong()));
306 selector.matchTcpDst(TpPort.tpPort((int) fiveTuple.portDst().toLong()));
307 } else {
308 // For udp packets take the port information from flow classifier
309 List<TpPort> srcPortRange = new LinkedList<>();
310 List<TpPort> dstPortRange = new LinkedList<>();
311 if ((flowClassifier.minSrcPortRange() != 0) && flowClassifier.maxSrcPortRange() != 0
312 && flowClassifier.minDstPortRange() != 0 && flowClassifier.maxDstPortRange() != 0) {
313
314 for (int port = flowClassifier.minSrcPortRange(); port <= flowClassifier.maxSrcPortRange(); port++) {
315 srcPortRange.add(TpPort.tpPort(port));
316 }
317 for (int port = flowClassifier.minDstPortRange(); port <= flowClassifier.maxDstPortRange(); port++) {
318 dstPortRange.add(TpPort.tpPort(port));
319 }
320 }
321
322 for (TpPort inPort : srcPortRange) {
323 selector.matchUdpSrc(inPort);
324 }
325 for (TpPort outPort : dstPortRange) {
326 selector.matchUdpDst(outPort);
327 }
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530328 }
329 return selector;
330 }
331
332 /**
333 * Pack traffic treatment.
334 *
335 * @param deviceId device id
Phaneendra Mandab8889b82016-03-04 14:13:10 +0530336 * @param port port number
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530337 * @param nshDstPort vxlan tunnel port for nsh header
Jonathan Hart51539b82015-10-29 09:53:04 -0700338 * @param nshSpi nsh spi
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530339 * @param flowClassifier flow-classifier
Phaneendra Mandab8889b82016-03-04 14:13:10 +0530340 * @param isSameOvs whether the next service function is in same ovs
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530341 * @return traffic treatment
342 */
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530343 public TrafficTreatment.Builder packTrafficTreatment(DeviceId deviceId, PortNumber port,
344 TpPort nshDstPort, NshServicePathId nshSpi,
345 FlowClassifier flowClassifier, boolean isSameOvs) {
346
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530347 TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
Mahesh Poojary S96cdcd22015-12-10 11:01:30 +0530348
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530349 if (isSameOvs) {
Mahesh Poojary S96cdcd22015-12-10 11:01:30 +0530350 treatmentBuilder.setOutput(port);
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530351 } else {
352 treatmentBuilder.setVlanId((VlanId.vlanId(Short.parseShort((vtnRscService
353 .getL3vni(flowClassifier.tenantId()).toString())))));
354 treatmentBuilder.setUdpDst(nshDstPort);
Mahesh Poojary S96cdcd22015-12-10 11:01:30 +0530355 }
356
357 // Set NSH
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530358 DriverHandler handler = driverService.createHandler(deviceId);
359 ExtensionTreatmentResolver resolver = handler.behaviour(ExtensionTreatmentResolver.class);
360 ExtensionTreatment nspIdTreatment = resolver.getExtensionInstruction(NICIRA_SET_NSH_SPI.type());
361 ExtensionTreatment nsiIdTreatment = resolver.getExtensionInstruction(NICIRA_SET_NSH_SI.type());
362
363 treatmentBuilder.extension(nspIdTreatment, deviceId);
364 treatmentBuilder.extension(nsiIdTreatment, deviceId);
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530365
366 try {
Jonathan Hart51539b82015-10-29 09:53:04 -0700367 nspIdTreatment.setPropertyValue("nshSpi", nshSpi);
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530368 } catch (Exception e) {
369 log.error("Failed to get extension instruction to set Nsh Spi Id {}", deviceId);
370 }
371 try {
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530372 nsiIdTreatment.setPropertyValue("nshSi", NshServiceIndex.of(NSH_SI_ID));
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530373 } catch (Exception e) {
374 log.error("Failed to get extension instruction to set Nsh Si Id {}", deviceId);
375 }
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530376
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530377 return treatmentBuilder;
378 }
379
380 /**
381 * Send service-function-forwarder to OVS.
382 *
383 * @param selector traffic selector
384 * @param treatment traffic treatment
385 * @param deviceId device id
386 * @param type operation type
Phaneendra Manda299877f2016-04-13 23:28:03 +0530387 * @param priority priority of classifier
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530388 */
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530389 public void sendServiceFunctionClassifier(TrafficSelector.Builder selector, TrafficTreatment.Builder treatment,
Phaneendra Manda299877f2016-04-13 23:28:03 +0530390 DeviceId deviceId, Objective.Operation type, int priority) {
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530391 log.info("Sending flow to service function classifier. Selector {}, Treatment {}",
392 selector.toString(), treatment.toString());
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530393 ForwardingObjective.Builder objective = DefaultForwardingObjective.builder().withTreatment(treatment.build())
Mahesh Poojary S96cdcd22015-12-10 11:01:30 +0530394 .withSelector(selector.build()).fromApp(appId).makePermanent().withFlag(Flag.VERSATILE)
Phaneendra Manda299877f2016-04-13 23:28:03 +0530395 .withPriority(priority);
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530396
397 if (type.equals(Objective.Operation.ADD)) {
398 log.debug("flowClassifierRules-->ADD");
399 flowObjectiveService.forward(deviceId, objective.add());
400 } else {
401 log.debug("flowClassifierRules-->REMOVE");
402 flowObjectiveService.forward(deviceId, objective.remove());
403 }
404 }
405}