Bug 4996 - Wrong flows when using SFC coexistence
[ovsdb.git] / openstack / net-virt-sfc / impl / src / main / java / org / opendaylight / ovsdb / openstack / netvirt / sfc / workaround / NetvirtSfcWorkaroundOF13Provider.java
1 /*
2  * Copyright © 2015 Red Hat, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.ovsdb.openstack.netvirt.sfc.workaround;
10
11 import com.google.common.base.Preconditions;
12 import java.util.List;
13 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
14 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
15 import org.opendaylight.ovsdb.openstack.netvirt.api.Constants;
16 import org.opendaylight.ovsdb.openstack.netvirt.api.NodeCacheManager;
17 import org.opendaylight.ovsdb.openstack.netvirt.api.OvsdbTables;
18 import org.opendaylight.ovsdb.openstack.netvirt.api.Southbound;
19 import org.opendaylight.ovsdb.openstack.netvirt.sfc.INetvirtSfcOF13Provider;
20 import org.opendaylight.ovsdb.openstack.netvirt.sfc.ISfcClassifierService;
21 import org.opendaylight.ovsdb.openstack.netvirt.sfc.NshUtils;
22 import org.opendaylight.ovsdb.openstack.netvirt.sfc.SfcUtils;
23 import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
24 import org.opendaylight.ovsdb.utils.servicehelper.ServiceHelper;
25 import org.opendaylight.sfc.provider.api.SfcProviderRenderedPathAPI;
26 import org.opendaylight.sfc.provider.api.SfcProviderServiceForwarderAPI;
27 import org.opendaylight.sfc.provider.api.SfcProviderServiceFunctionAPI;
28 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sl.rev140701.data.plane.locator.locator.type.Ip;
29 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.rsp.rev140701.CreateRenderedPathInput;
30 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.rsp.rev140701.CreateRenderedPathInputBuilder;
31 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.rsp.rev140701.rendered.service.path.first.hop.info.RenderedServicePathFirstHop;
32 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.rsp.rev140701.rendered.service.paths.RenderedServicePath;
33 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.rsp.rev140701.rendered.service.paths.rendered.service.path.RenderedServicePathHop;
34 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sf.rev140701.service.functions.ServiceFunction;
35 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sff.rev140701.service.function.forwarders.ServiceFunctionForwarder;
36 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfp.rev140701.service.function.paths.ServiceFunctionPath;
37 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev150317.access.lists.Acl;
38 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev150317.access.lists.acl.access.list.entries.Ace;
39 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev150317.access.lists.acl.access.list.entries.ace.Matches;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.sfc.acl.rev150105.RedirectToSfc;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.sfc.classifier.rev150105.Classifiers;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.sfc.classifier.rev150105.classifiers.Classifier;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.sfc.classifier.rev150105.classifiers.classifier.Bridges;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.sfc.classifier.rev150105.classifiers.classifier.bridges.Bridge;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.sfc.classifier.rev150105.classifiers.classifier.sffs.Sff;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbTerminationPointAugmentation;
49 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
50 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
51 import org.osgi.framework.ServiceReference;
52 import org.slf4j.Logger;
53 import org.slf4j.LoggerFactory;
54
55 public class NetvirtSfcWorkaroundOF13Provider implements INetvirtSfcOF13Provider {
56     private static final Logger LOG = LoggerFactory.getLogger(NetvirtSfcWorkaroundOF13Provider.class);
57     private volatile NodeCacheManager nodeCacheManager;
58     private volatile Southbound southbound;
59     private volatile ISfcClassifierService sfcClassifierService;
60     private static final short SFC_TABLE = 150;
61     private MdsalUtils mdsalUtils;
62     private SfcUtils sfcUtils;
63     private DataBroker dataBroker;
64     private static final String VXGPE = "vxgpe";
65     public static final String TUNNEL_ENDPOINT_KEY = "local_ip";
66
67     public NetvirtSfcWorkaroundOF13Provider(final DataBroker dataBroker, MdsalUtils mdsalUtils, SfcUtils sfcUtils) {
68         Preconditions.checkNotNull(dataBroker, "Input dataBroker cannot be NULL!");
69         Preconditions.checkNotNull(mdsalUtils, "Input mdsalUtils cannot be NULL!");
70         Preconditions.checkNotNull(sfcUtils, "Input sfcUtils cannot be NULL!");
71
72         this.dataBroker = dataBroker;
73         this.mdsalUtils = mdsalUtils;
74         this.sfcUtils = sfcUtils;
75     }
76
77     public void setSfcClassifierService(ISfcClassifierService sfcClassifierService) {
78         this.sfcClassifierService = sfcClassifierService;
79     }
80
81     @Override
82     public void addClassifierRules(Bridge bridge, Acl acl) {
83
84     }
85
86     @Override
87     public void addClassifierRules(Bridges bridges, Acl acl) {
88         Preconditions.checkNotNull(bridges, "Input bridges cannot be NULL!");
89         Preconditions.checkNotNull(acl, "Input acl cannot be NULL!");
90     }
91
92     @Override
93     public void removeClassifierRules(Sff sff, Acl acl) {
94
95     }
96
97     @Override
98     public void addClassifierRules(Acl acl) {
99         String aclName = acl.getAclName();
100         Classifiers classifiers = mdsalUtils.read(LogicalDatastoreType.CONFIGURATION, sfcUtils.getClassifierIid());
101         if (classifiers == null) {
102             LOG.debug("addClassifierRules: No Classifiers found");
103             return;
104         }
105
106         LOG.debug("addClassifierRules: Classifiers: {}", classifiers);
107         for (Classifier classifier : classifiers.getClassifier()) {
108             if (classifier.getAcl().equals(aclName)) {
109                 for (Ace ace : acl.getAccessListEntries().getAce()) {
110                     processAclEntry(ace);
111                 }
112             }
113         }
114     }
115
116     @Override
117     public void removeClassifierRules(Acl acl) {
118
119     }
120
121     @Override
122     public void removeRsp(RenderedServicePath change) {
123         LOG.info("removeRsp not implemented yet");
124         sfcClassifierService.clearFlows(dataBroker, change.getName().getValue());
125     }
126
127     @Override
128     public void updateRsp(RenderedServicePath change) {
129         LOG.info("updateRsp not implemented yet");
130     }
131
132     private void processAclEntry(Ace entry) {
133         Matches matches = entry.getMatches();
134         Preconditions.checkNotNull(matches, "ACL Entry cannot be null!");
135
136         RenderedServicePath rsp = getRenderedServicePath(entry);
137         if (rsp == null) {
138             LOG.warn("Failed to get renderedServicePatch for entry: {}", entry);
139             return;
140         }
141
142         handleRenderedServicePath(rsp, entry);
143     }
144
145     private void handleRenderedServicePath(RenderedServicePath rsp) {
146         LOG.info("handleRenderedServicePath: RSP: {}", rsp);
147         Ace entry = getAceFromRenderedServicePath(rsp);
148         if (entry == null) {
149             LOG.warn("handleRenderedServicePath: failed to get acl entry");
150             return;
151         }
152
153         handleRenderedServicePath(rsp, entry);
154     }
155
156     private void handleRenderedServicePath(RenderedServicePath rsp, Ace entry) {
157         LOG.info("handleRenderedServicePath: RSP: {}, Ace: {}", rsp, entry);
158
159         Matches matches = entry.getMatches();
160         if (matches == null) {
161             LOG.warn("processAclEntry: matches not found");
162             return;
163         }
164
165         List<RenderedServicePathHop> pathHopList = rsp.getRenderedServicePathHop();
166         if (pathHopList.isEmpty()) {
167             LOG.warn("handleRenderedServicePath: RSP {} has empty hops!!", rsp.getName());
168             return;
169         }
170         LOG.info("handleRenderedServicePath: pathHopList: {}", pathHopList);
171
172         RenderedServicePathFirstHop firstRspHop = SfcProviderRenderedPathAPI
173                 .readRenderedServicePathFirstHop(rsp.getName());
174         LOG.info("handleRenderedServicePath: firstRspHop: {}", firstRspHop);
175
176         RenderedServicePathHop firstHop = pathHopList.get(0);
177         RenderedServicePathHop lastHop = pathHopList.get(pathHopList.size()-1);
178
179         final List<Node> bridgeNodes = nodeCacheManager.getBridgeNodes();
180         if (bridgeNodes == null || bridgeNodes.isEmpty()) {
181             LOG.warn("handleRenderedServicePath: There are no bridges to process");
182             return;
183         }
184         for (RenderedServicePathHop hop : pathHopList) {
185             for (Node bridgeNode : bridgeNodes) {
186                 // ignore bridges other than br-int
187                 // TODO: Get bridge name from DPL, rework this loop to use DPL list
188                 OvsdbBridgeAugmentation ovsdbBridgeAugmentation = southbound.getBridge(bridgeNode, "br-int");
189                 if (ovsdbBridgeAugmentation == null) {
190                     continue;
191                 }
192                 // TODO: Get port name from the DPL
193                 long vxGpeOfPort = getOFPort(bridgeNode, VXGPE);
194                 if (vxGpeOfPort == 0L) {
195                     LOG.warn("handleRenderedServicePath: Could not identify gpe vtep {} -> OF ({}) on {}",
196                             VXGPE, vxGpeOfPort, bridgeNode);
197                     continue;
198                 }
199                 long dataPathId = southbound.getDataPathId(bridgeNode);
200                 if (dataPathId == 0L) {
201                     LOG.warn("handleRenderedServicePath: Could not identify datapathId on {}", bridgeNode);
202                     continue;
203                 }
204
205                 ServiceFunction serviceFunction =
206                         SfcProviderServiceFunctionAPI.readServiceFunction(firstHop.getServiceFunctionName());
207                 if (serviceFunction == null) {
208                     LOG.warn("handleRenderedServicePath: Could not identify ServiceFunction {} on {}",
209                             firstHop.getServiceFunctionName().getValue(), bridgeNode);
210                     continue;
211                 }
212                 ServiceFunctionForwarder serviceFunctionForwarder =
213                         SfcProviderServiceForwarderAPI
214                                 .readServiceFunctionForwarder(hop.getServiceFunctionForwarder());
215                 if (serviceFunctionForwarder == null) {
216                     LOG.warn("handleRenderedServicePath: Could not identify ServiceFunctionForwarder {} on {}",
217                             firstHop.getServiceFunctionName().getValue(), bridgeNode);
218                     continue;
219                 }
220
221                 handleSf(bridgeNode, serviceFunction, rsp);
222                 handleSff(bridgeNode, serviceFunctionForwarder, serviceFunction, hop, firstHop, lastHop,
223                         entry.getRuleName(), matches, vxGpeOfPort, rsp);
224                 if (firstHop == lastHop) {
225                     handleSff(bridgeNode, serviceFunctionForwarder, serviceFunction, hop, null, lastHop,
226                             entry.getRuleName(), matches, vxGpeOfPort, rsp);
227                 }
228             }
229         }
230     }
231
232     private void handleSff(Node bridgeNode, ServiceFunctionForwarder serviceFunctionForwarder,
233                            ServiceFunction serviceFunction,
234                            RenderedServicePathHop hop,
235                            RenderedServicePathHop firstHop,
236                            RenderedServicePathHop lastHop,
237                            String ruleName, Matches matches,
238                            long vxGpeOfPort, RenderedServicePath rsp) {
239         long dataPathId = southbound.getDataPathId(bridgeNode);
240
241         if (hop == firstHop) {
242             LOG.info("handleSff: first hop processing {} - {}",
243                     bridgeNode.getNodeId().getValue(), serviceFunctionForwarder.getName().getValue());
244             NshUtils nshHeader = new NshUtils();
245             nshHeader.setNshNsp(rsp.getPathId());
246             nshHeader.setNshNsi(firstHop.getServiceIndex());
247             if (isSffOnBridge(bridgeNode, serviceFunctionForwarder)) {
248                 LOG.info("handleSff: sff and bridge are the same: {} - {}, skipping first sff",
249                         bridgeNode.getNodeId().getValue(), serviceFunctionForwarder.getName().getValue());
250                 Ip ip = sfcUtils.getSfIp(serviceFunction);
251                 nshHeader.setNshTunIpDst(ip.getIp().getIpv4Address());
252                 nshHeader.setNshTunUdpPort(ip.getPort());
253             } else {
254                 LOG.info("handleSff: sff and bridge are not the same: {} - {}, sending to first sff",
255                         bridgeNode.getNodeId().getValue(), serviceFunctionForwarder.getName().getValue());
256                 Ip ip = sfcUtils.getSffIp(serviceFunctionForwarder);
257                 nshHeader.setNshTunIpDst(ip.getIp().getIpv4Address());
258                 nshHeader.setNshTunUdpPort(ip.getPort());
259             }
260             sfcClassifierService.programIngressClassifier(dataPathId, ruleName, matches,
261                     rsp.getPathId(), rsp.getStartingIndex(),
262                     nshHeader, vxGpeOfPort, rsp.getName().getValue(), true);
263         } else if (hop == lastHop) {
264             LOG.info("handleSff: last hop processing {} - {}",
265                     bridgeNode.getNodeId().getValue(), serviceFunctionForwarder.getName().getValue());
266             short lastServiceindex = (short)((lastHop.getServiceIndex()).intValue() - 1);
267             String sfDplName = sfcUtils.getSfDplName(serviceFunction);
268             long sfOfPort = getSfPort(bridgeNode, sfDplName);
269             // TODO: Coexistence: SFC flows should take this using new egressTable REST
270             sfcClassifierService.programEgressClassifier(dataPathId, vxGpeOfPort, rsp.getPathId(),
271                     lastServiceindex, sfOfPort, 0, rsp.getName().getValue(), true);
272             // TODO: Coexistence: This flow should like like one above, change port, add reg0=1, resubmit
273             sfcClassifierService.programEgressClassifierBypass(dataPathId, vxGpeOfPort, rsp.getPathId(),
274                     lastServiceindex, sfOfPort, 0, rsp.getName().getValue(), true);
275         } else {
276             // add typical sff flows
277         }
278
279         // TODO: Coexistence: SFC flows should take this using new tableOffset REST
280         //sfcClassifierService.programSfcTable(dataPathId, vxGpeOfPort, SFC_TABLE, true);
281     }
282
283     void handleSf(Node bridgeNode, ServiceFunction serviceFunction, RenderedServicePath rsp) {
284         if (isSfOnBridge(bridgeNode, serviceFunction)) {
285             LOG.info("handleSf: sf and bridge are on the same node: {} - {}, adding workaround and arp",
286                     bridgeNode.getNodeId().getValue(), serviceFunction.getName().getValue());
287             long dataPathId = southbound.getDataPathId(bridgeNode);
288             Ip ip = sfcUtils.getSfIp(serviceFunction);
289             String sfIpAddr = String.valueOf(ip.getIp().getValue());
290             int sfIpPort = ip.getPort().getValue(); //GPE_PORT
291             String sfDplName = sfcUtils.getSfDplName(serviceFunction);
292             long sfOfPort = getSfPort(bridgeNode, sfDplName);
293             String sfMac = getMacFromExternalIds(bridgeNode, sfDplName);
294             if (sfMac == null) {
295                 LOG.warn("handleSff: could not find mac for {} on {}", sfDplName, bridgeNode);
296                 return;
297             }
298             //should be sffdplport, but they should all be the same 6633/4790
299             // TODO: Coexistence: SFC flows should take this using new sf dpl augmentation
300             //sfcClassifierService.program_sfEgress(dataPathId, sfIpPort, true);
301             //sfcClassifierService.program_sfIngress(dataPathId, sfIpPort, sfOfPort, sfIpAddr, sfDplName, true);
302             sfcClassifierService.programStaticArpEntry(dataPathId, 0L, sfMac, sfIpAddr,
303                     rsp.getName().getValue(), true);
304         } else {
305             LOG.info("handleSf: sf and bridge are not on the same node: {} - {}, do nothing",
306                     bridgeNode.getNodeId().getValue(), serviceFunction.getName().getValue());
307         }
308     }
309
310     private boolean isSffOnBridge(Node bridgeNode, ServiceFunctionForwarder serviceFunctionForwarder) {
311         String localIp = "";
312         Ip ip = sfcUtils.getSffIp(serviceFunctionForwarder);
313         Node ovsdbNode = southbound.readOvsdbNode(bridgeNode);
314         if (ovsdbNode != null) {
315             localIp = getLocalip(ovsdbNode);
316         }
317         LOG.info("isSffOnBridge: {}: {}, localIp: {}, sff ip: {}",
318                 bridgeNode.getNodeId().getValue(),
319                 localIp.equals(String.valueOf(ip.getIp().getValue())),
320                 localIp, ip.getIp().getValue());
321         return localIp.equals(String.valueOf(ip.getIp().getValue()));
322     }
323
324     private String getLocalip(Node ovsdbNode) {
325         Preconditions.checkNotNull(ovsdbNode, "The ovsdbNode was null");
326         String localIp = null;
327         if (ovsdbNode != null) {
328             OvsdbNodeAugmentation ovsdbNodeAugmentation = ovsdbNode.getAugmentation(OvsdbNodeAugmentation.class);
329             if (ovsdbNodeAugmentation != null && ovsdbNodeAugmentation.getOpenvswitchOtherConfigs() != null) {
330                 localIp = southbound.getOtherConfig(ovsdbNode, OvsdbTables.OPENVSWITCH, TUNNEL_ENDPOINT_KEY);
331             }
332         }
333         if (localIp == null) {
334             LOG.warn("local_ip was not found for node: {}", ovsdbNode);
335             localIp = "";
336         }
337         return localIp;
338     }
339
340     private boolean isSfOnBridge(Node bridgeNode, ServiceFunction serviceFunction) {
341         String sfDplName = sfcUtils.getSfDplName(serviceFunction);
342         long sfOfPort = getSfPort(bridgeNode, sfDplName);
343         LOG.info("isSfOnBridge: {}: {}, sfOfPort: {}", bridgeNode.getNodeId().getValue(), sfOfPort != 0L, sfOfPort);
344         return sfOfPort != 0L;
345     }
346
347     private Ace getAceFromRenderedServicePath(RenderedServicePath rsp) {
348         Preconditions.checkNotNull(rsp, "RSP cannot be null");
349         Ace ace = null;
350         String rspName = rsp.getName().getValue();
351         String rspNameSuffix = "_rsp";
352         String sfcName = rspName.substring(0, rspName.length() - rspNameSuffix.length());
353         LOG.info("getAceFromRenderedServicePath: rsp: {}, sfcName: {}", rsp, sfcName);
354         ace = sfcUtils.getAce(sfcName);
355
356         return ace;
357     }
358
359     private RenderedServicePath getRenderedServicePath (Ace entry) {
360         RenderedServicePath rsp = null;
361         RedirectToSfc sfcRedirect = entry.getActions().getAugmentation(RedirectToSfc.class);
362         LOG.debug("Processing ACL entry = {} sfcRedirect = {}", entry.getRuleName(), sfcRedirect);
363         if (sfcRedirect == null) {
364             LOG.warn("processAClEntry: sfcRedirect is null");
365             return null;
366         }
367
368         if (sfcRedirect.getRspName() != null) {
369             rsp = getRenderedServicePathFromRsp(sfcRedirect.getRspName());
370         } else if (sfcRedirect.getSfpName() != null) {
371             LOG.warn("getRenderedServicePath: sfp not handled yet");
372         } else {
373             rsp = getRenderedServicePathFromSfc(entry);
374         }
375         LOG.info("getRenderedServicePath: rsp: {}", rsp);
376         return rsp;
377     }
378
379     private RenderedServicePath getRenderedServicePathFromRsp(String rspName) {
380         return sfcUtils.getRsp(rspName);
381     }
382
383     private RenderedServicePath getRenderedServicePathFromSfc (Ace entry) {
384         RedirectToSfc sfcRedirect = entry.getActions().getAugmentation(RedirectToSfc.class);
385         LOG.debug("Processing ACL entry = {} sfcRedirect = {}", entry.getRuleName(), sfcRedirect);
386         if (sfcRedirect == null) {
387             LOG.warn("processAClEntry: sfcRedirect is null");
388             return null;
389         }
390
391         String sfcName = sfcRedirect.getSfcName();
392         ServiceFunctionPath sfp = sfcUtils.getSfp(sfcName);
393         if (sfp == null || sfp.getName() == null) {
394             LOG.warn("There is no configured SFP with sfcName = {}; so skip installing the ACL entry!!", sfcName);
395             return null;
396         }
397
398         LOG.debug("Processing Redirect to SFC = {}, SFP = {}", sfcName, sfp);
399         // If RSP doesn't exist, create an RSP.
400         String sfpName = sfp.getName().getValue();
401         RenderedServicePath rsp = sfcUtils.getRspforSfp(sfpName);
402         String rspName = sfp.getName().getValue() + "_rsp";
403         if (rsp == null) {
404             LOG.info("No configured RSP corresponding to SFP = {}, Creating new RSP = {}", sfpName, rspName);
405             CreateRenderedPathInput rspInput = new CreateRenderedPathInputBuilder()
406                     .setParentServiceFunctionPath(sfpName)
407                     .setName(rspName)
408                     .setSymmetric(sfp.isSymmetric())
409                     .build();
410             rsp = SfcProviderRenderedPathAPI.createRenderedServicePathAndState(sfp, rspInput);
411             if (rsp == null) {
412                 LOG.warn("failed to add RSP");
413                 return null;
414             }
415
416             // If SFP is symmetric, create RSP in the reverse direction.
417             if (sfp.isSymmetric()) {
418                 LOG.info("SFP = {} is symmetric, installing RSP in the reverse direction!!", sfpName);
419                 String rspNameRev = rspName + "-Reverse";
420                 RenderedServicePath rspReverse = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL,
421                         sfcUtils.getRspId(rspNameRev));
422                 if (rspReverse == null) {
423                     rspReverse = SfcProviderRenderedPathAPI.createSymmetricRenderedServicePathAndState(rsp);
424                     if (rspReverse == null) {
425                         LOG.warn("failed to add reverse RSP");
426                         return null;
427                     }
428                 }
429             }
430         }
431         return rsp;
432     }
433
434     private long getSfPort(Node bridgeNode, String sfPortName) {
435         return getOFPort(bridgeNode, sfPortName);
436     }
437
438     private long getOFPort(Node bridgeNode, String portName) {
439         long ofPort = 0L;
440         OvsdbTerminationPointAugmentation port =
441                 southbound.extractTerminationPointAugmentation(bridgeNode, portName);
442         if (port != null) {
443             ofPort = southbound.getOFPort(port);
444         }
445         if (ofPort == 0L) {
446             for (int i = 0; i < 5; i++) {
447                 LOG.info("Looking for ofPort {}, try: {}", portName, i);
448                 TerminationPoint tp = southbound.readTerminationPoint(bridgeNode, null, portName);
449                 if (tp != null) {
450                     port = tp.getAugmentation(OvsdbTerminationPointAugmentation.class);
451                     if (port != null) {
452                         ofPort = southbound.getOFPort(port);
453                         LOG.info("found ofPort {} - {}, try: {}", portName, ofPort, i);
454                         break;
455                     }
456                 }
457                 try {
458                     Thread.sleep(1000);
459                 } catch (InterruptedException e) {
460                     LOG.error("Interrupted while waiting for ofPort {}", portName, e);
461                 }
462             }
463         }
464         return ofPort;
465     }
466
467     private String getMacFromExternalIds(Node bridgeNode, String portName) {
468         String mac = null;
469         OvsdbTerminationPointAugmentation port = southbound.getTerminationPointOfBridge(bridgeNode, portName);
470         LOG.info("getMac: portName: {}, bridgeNode: {},,, port: {}", portName, bridgeNode, port);
471         if (port != null && port.getInterfaceExternalIds() != null) {
472             mac = southbound.getInterfaceExternalIdsValue(port, Constants.EXTERNAL_ID_VM_MAC);
473         }
474         return mac;
475     }
476
477     @Override
478     public void setDependencies(ServiceReference serviceReference) {
479         nodeCacheManager = (NodeCacheManager) ServiceHelper.getGlobalInstance(NodeCacheManager.class, this);
480         southbound = (Southbound) ServiceHelper.getGlobalInstance(Southbound.class, this);
481         sfcClassifierService =
482                 (ISfcClassifierService) ServiceHelper.getGlobalInstance(ISfcClassifierService.class, this);
483         LOG.info("sfcClassifierService= {}", sfcClassifierService);
484     }
485 }