blob: dbae14c75a8a9c0671119593f583ea7c61e32be3 [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);
226 sendServiceFunctionClassifier(selector, treatment, deviceId, type);
227 } 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.
232 sendServiceFunctionClassifier(selector, treatment, deviceId, type);
233 } 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.
238 sendServiceFunctionClassifier(selector, treatment, deviceId, type);
239
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());
247 sendServiceFunctionClassifier(selectorDst, treatmentDst, deviceIdfromPortPair, type);
248 }
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530249 }
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530250 return host.location();
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530251 }
252
253 /**
254 * Pack Traffic selector.
255 *
256 * @param flowClassifier flow-classifier
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530257 * @param fiveTuple five tuple info for the packet
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530258 * @return traffic selector
259 */
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530260 public TrafficSelector.Builder packTrafficSelector(FlowClassifier flowClassifier, FiveTuple fiveTuple) {
261
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530262 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
263
Mahesh Poojary S96cdcd22015-12-10 11:01:30 +0530264 if ((flowClassifier.srcIpPrefix() != null) && (flowClassifier.srcIpPrefix().prefixLength() != 0)) {
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530265 selector.matchIPSrc(flowClassifier.srcIpPrefix());
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530266 } else if (fiveTuple != null && fiveTuple.ipSrc() != null) {
267 selector.matchIPSrc(IpPrefix.valueOf(fiveTuple.ipSrc(), 24));
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530268 }
Mahesh Poojary S96cdcd22015-12-10 11:01:30 +0530269
270 if ((flowClassifier.dstIpPrefix() != null) && (flowClassifier.dstIpPrefix().prefixLength() != 0)) {
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530271 selector.matchIPDst(flowClassifier.dstIpPrefix());
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530272 } else if (fiveTuple != null && fiveTuple.ipDst() != null) {
273 selector.matchIPDst(IpPrefix.valueOf(fiveTuple.ipDst(), 24));
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530274 }
275
Mahesh Poojary S96cdcd22015-12-10 11:01:30 +0530276 if ((flowClassifier.protocol() != null) && (!flowClassifier.protocol().isEmpty())) {
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530277 if (flowClassifier.protocol().equalsIgnoreCase("TCP")) {
278 selector.add(Criteria.matchIPProtocol(IPv4.PROTOCOL_TCP));
279 } else if (flowClassifier.protocol().equalsIgnoreCase("UDP")) {
280 selector.add(Criteria.matchIPProtocol(IPv4.PROTOCOL_UDP));
281 }
282 } else if (fiveTuple != null && fiveTuple.protocol() != 0) {
283 selector.add(Criteria.matchIPProtocol(fiveTuple.protocol()));
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530284 }
Mahesh Poojary S96cdcd22015-12-10 11:01:30 +0530285
286 if (((flowClassifier.etherType() != null) && (!flowClassifier.etherType().isEmpty()))
287 && (flowClassifier.etherType().equals("IPv4") || flowClassifier.etherType().equals("IPv6"))) {
288 if (flowClassifier.etherType().equals("IPv4")) {
289 selector.matchEthType(Ethernet.TYPE_IPV4);
290 } else {
291 selector.matchEthType(Ethernet.TYPE_IPV6);
292 }
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530293 }
294
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530295 if ((flowClassifier.srcPort() != null) && (!flowClassifier.srcPort().portId().isEmpty())) {
296 VirtualPortId vPortId = VirtualPortId.portId(flowClassifier.srcPort().portId());
297 MacAddress macAddress = virtualPortService.getPort(vPortId).macAddress();
298 Host host = hostService.getHost(HostId.hostId(macAddress));
299 selector.matchInPort(host.location().port());
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530300 }
301
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530302 // Take the port information from five tuple only when the protocol is TCP.
303 if (fiveTuple != null && fiveTuple.protocol() == IPv4.PROTOCOL_TCP) {
304 selector.matchTcpSrc(TpPort.tpPort((int) fiveTuple.portSrc().toLong()));
305 selector.matchTcpDst(TpPort.tpPort((int) fiveTuple.portDst().toLong()));
306 } else {
307 // For udp packets take the port information from flow classifier
308 List<TpPort> srcPortRange = new LinkedList<>();
309 List<TpPort> dstPortRange = new LinkedList<>();
310 if ((flowClassifier.minSrcPortRange() != 0) && flowClassifier.maxSrcPortRange() != 0
311 && flowClassifier.minDstPortRange() != 0 && flowClassifier.maxDstPortRange() != 0) {
312
313 for (int port = flowClassifier.minSrcPortRange(); port <= flowClassifier.maxSrcPortRange(); port++) {
314 srcPortRange.add(TpPort.tpPort(port));
315 }
316 for (int port = flowClassifier.minDstPortRange(); port <= flowClassifier.maxDstPortRange(); port++) {
317 dstPortRange.add(TpPort.tpPort(port));
318 }
319 }
320
321 for (TpPort inPort : srcPortRange) {
322 selector.matchUdpSrc(inPort);
323 }
324 for (TpPort outPort : dstPortRange) {
325 selector.matchUdpDst(outPort);
326 }
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530327 }
328 return selector;
329 }
330
331 /**
332 * Pack traffic treatment.
333 *
334 * @param deviceId device id
Phaneendra Mandab8889b82016-03-04 14:13:10 +0530335 * @param port port number
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530336 * @param nshDstPort vxlan tunnel port for nsh header
Jonathan Hart51539b82015-10-29 09:53:04 -0700337 * @param nshSpi nsh spi
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530338 * @param flowClassifier flow-classifier
Phaneendra Mandab8889b82016-03-04 14:13:10 +0530339 * @param isSameOvs whether the next service function is in same ovs
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530340 * @return traffic treatment
341 */
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530342 public TrafficTreatment.Builder packTrafficTreatment(DeviceId deviceId, PortNumber port,
343 TpPort nshDstPort, NshServicePathId nshSpi,
344 FlowClassifier flowClassifier, boolean isSameOvs) {
345
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530346 TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
Mahesh Poojary S96cdcd22015-12-10 11:01:30 +0530347
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530348 if (isSameOvs) {
Mahesh Poojary S96cdcd22015-12-10 11:01:30 +0530349 treatmentBuilder.setOutput(port);
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530350 } else {
351 treatmentBuilder.setVlanId((VlanId.vlanId(Short.parseShort((vtnRscService
352 .getL3vni(flowClassifier.tenantId()).toString())))));
353 treatmentBuilder.setUdpDst(nshDstPort);
Mahesh Poojary S96cdcd22015-12-10 11:01:30 +0530354 }
355
356 // Set NSH
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530357 DriverHandler handler = driverService.createHandler(deviceId);
358 ExtensionTreatmentResolver resolver = handler.behaviour(ExtensionTreatmentResolver.class);
359 ExtensionTreatment nspIdTreatment = resolver.getExtensionInstruction(NICIRA_SET_NSH_SPI.type());
360 ExtensionTreatment nsiIdTreatment = resolver.getExtensionInstruction(NICIRA_SET_NSH_SI.type());
361
362 treatmentBuilder.extension(nspIdTreatment, deviceId);
363 treatmentBuilder.extension(nsiIdTreatment, deviceId);
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530364
365 try {
Jonathan Hart51539b82015-10-29 09:53:04 -0700366 nspIdTreatment.setPropertyValue("nshSpi", nshSpi);
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530367 } catch (Exception e) {
368 log.error("Failed to get extension instruction to set Nsh Spi Id {}", deviceId);
369 }
370 try {
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530371 nsiIdTreatment.setPropertyValue("nshSi", NshServiceIndex.of(NSH_SI_ID));
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530372 } catch (Exception e) {
373 log.error("Failed to get extension instruction to set Nsh Si Id {}", deviceId);
374 }
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530375
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530376 return treatmentBuilder;
377 }
378
379 /**
380 * Send service-function-forwarder to OVS.
381 *
382 * @param selector traffic selector
383 * @param treatment traffic treatment
384 * @param deviceId device id
385 * @param type operation type
386 */
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530387 public void sendServiceFunctionClassifier(TrafficSelector.Builder selector, TrafficTreatment.Builder treatment,
388 DeviceId deviceId, Objective.Operation type) {
389 log.info("Sending flow to service function classifier. Selector {}, Treatment {}",
390 selector.toString(), treatment.toString());
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530391 ForwardingObjective.Builder objective = DefaultForwardingObjective.builder().withTreatment(treatment.build())
Mahesh Poojary S96cdcd22015-12-10 11:01:30 +0530392 .withSelector(selector.build()).fromApp(appId).makePermanent().withFlag(Flag.VERSATILE)
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530393 .withPriority(FLOW_CLASSIFIER_PRIORITY);
Bharat Saraswal0fa12e92015-12-04 02:58:01 +0530394
395 if (type.equals(Objective.Operation.ADD)) {
396 log.debug("flowClassifierRules-->ADD");
397 flowObjectiveService.forward(deviceId, objective.add());
398 } else {
399 log.debug("flowClassifierRules-->REMOVE");
400 flowObjectiveService.forward(deviceId, objective.remove());
401 }
402 }
403}