2 * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
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
8 package org.opendaylight.vpnservice;
10 import org.opendaylight.vpnservice.utilities.InterfaceUtils;
12 import com.google.common.util.concurrent.FutureCallback;
13 import com.google.common.util.concurrent.Futures;
14 import com.google.common.util.concurrent.JdkFutureAdapters;
16 import org.opendaylight.controller.md.sal.binding.api.*;
17 import org.opendaylight.vpnservice.mdsalutil.*;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.OpState;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.OpStateBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.adjacency.list.AdjacencyKey;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnList;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnListBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.vpn.to.dpn.list.VpnInterfacesBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.vpn.to.dpn.list.VpnInterfacesKey;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.arputil.rev151126.OdlArputilService;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.arputil.rev151126.SendArpResponseInput;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.arputil.rev151126.SendArpResponseInputBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.servicebinding.rev151015.service.bindings.services.info.BoundServices;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.fibmanager.rev150330.FibEntries;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.fibmanager.rev150330.fibentries.VrfTables;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.fibmanager.rev150330.fibentries.VrfTablesBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.fibmanager.rev150330.fibentries.VrfTablesKey;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.fibmanager.rev150330.vrfentries.VrfEntry;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.fibmanager.rev150330.vrfentries.VrfEntryBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.fibmanager.rev150330.vrfentries.VrfEntryKey;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.IdManagerService;
42 import java.math.BigInteger;
43 import java.util.Collection;
44 import java.util.Iterator;
45 import java.util.List;
46 import java.util.ArrayList;
47 import java.util.concurrent.*;
49 import com.google.common.base.Optional;
51 import org.opendaylight.bgpmanager.api.IBgpManager;
52 import org.opendaylight.fibmanager.api.IFibManager;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rpcs.rev151003.OdlInterfaceRpcService;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.ItmRpcService;
55 import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager;
56 import org.opendaylight.yangtools.concepts.ListenerRegistration;
57 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
58 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder;
59 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
60 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
61 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.adjacency.list.Adjacency;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.adjacency.list.AdjacencyBuilder;
64 import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.VpnInterfaces;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.Adjacencies;
66 import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.VpnAfConfig;
67 import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.VpnInstances;
68 import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance;
69 import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstanceKey;
70 import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface;
71 import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceKey;
72 import org.opendaylight.yangtools.yang.common.RpcError;
73 import org.opendaylight.yangtools.yang.common.RpcResult;
74 import org.slf4j.Logger;
75 import org.slf4j.LoggerFactory;
77 public class VpnInterfaceManager extends AbstractDataChangeListener<VpnInterface> implements AutoCloseable {
78 private static final Logger LOG = LoggerFactory.getLogger(VpnInterfaceManager.class);
79 private ListenerRegistration<DataChangeListener> listenerRegistration, opListenerRegistration;
80 private ConcurrentMap<String, Runnable> vpnIntfMap = new ConcurrentHashMap<String, Runnable>();
81 private ExecutorService executorService = Executors.newSingleThreadExecutor();
82 private final DataBroker broker;
83 private final IBgpManager bgpManager;
84 private IFibManager fibManager;
85 private IMdsalApiManager mdsalManager;
86 private OdlInterfaceRpcService interfaceManager;
87 private ItmRpcService itmProvider;
88 private IdManagerService idManager;
89 private OdlArputilService arpManager;
90 private InterfaceStateChangeListener interfaceListener;
91 private VpnInterfaceOpListener vpnInterfaceOpListener;
92 private ArpNotificationHandler arpNotificationHandler;
93 protected enum UpdateRouteAction {
94 ADVERTISE_ROUTE, WITHDRAW_ROUTE
97 * Responsible for listening to data change related to VPN Interface
98 * Bind VPN Service on the interface and informs the BGP service
100 * @param db - dataBroker service reference
102 public VpnInterfaceManager(final DataBroker db, final IBgpManager bgpManager, NotificationService notificationService) {
103 super(VpnInterface.class);
105 this.bgpManager = bgpManager;
106 interfaceListener = new InterfaceStateChangeListener(db, this);
107 vpnInterfaceOpListener = new VpnInterfaceOpListener();
108 arpNotificationHandler = new ArpNotificationHandler(this, broker);
109 notificationService.registerNotificationListener(arpNotificationHandler);
110 registerListener(db);
113 public void setMdsalManager(IMdsalApiManager mdsalManager) {
114 this.mdsalManager = mdsalManager;
117 public void setInterfaceManager(OdlInterfaceRpcService interfaceManager) {
118 this.interfaceManager = interfaceManager;
119 interfaceListener.setInterfaceManager(interfaceManager);
122 public void setITMProvider(ItmRpcService itmProvider) {
123 this.itmProvider = itmProvider;
126 public void setFibManager(IFibManager fibManager) {
127 this.fibManager = fibManager;
130 public void setIdManager(IdManagerService idManager) {
131 this.idManager = idManager;
134 public void setArpManager(OdlArputilService arpManager) {
135 this.arpManager = arpManager;
139 public void close() throws Exception {
140 if (listenerRegistration != null) {
142 listenerRegistration.close();
143 opListenerRegistration.close();
144 } catch (final Exception e) {
145 LOG.error("Error when cleaning up DataChangeListener.", e);
147 listenerRegistration = null;
148 opListenerRegistration = null;
150 LOG.info("VPN Interface Manager Closed");
153 private void registerListener(final DataBroker db) {
155 listenerRegistration = db.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION,
156 getWildCardPath(), VpnInterfaceManager.this, DataChangeScope.SUBTREE);
157 opListenerRegistration = db.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL,
158 getWildCardPath(), vpnInterfaceOpListener, DataChangeScope.SUBTREE);
159 } catch (final Exception e) {
160 LOG.error("VPN Service DataChange listener registration fail!", e);
161 throw new IllegalStateException("VPN Service registration Listener failed.", e);
165 private InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> getInterfaceListenerPath() {
166 return InstanceIdentifier.create(InterfacesState.class)
167 .child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.class);
171 protected void add(final InstanceIdentifier<VpnInterface> identifier,
172 final VpnInterface vpnInterface) {
173 LOG.trace("VPN Interface key: {} , value: {}", identifier, vpnInterface );
174 addInterface(identifier, vpnInterface);
177 private void addInterface(final InstanceIdentifier<VpnInterface> identifier,
178 final VpnInterface vpnInterface) {
179 LOG.trace("VPN Interface add event - key: {}, value: {}" ,identifier, vpnInterface );
180 final VpnInterfaceKey key = identifier.firstKeyOf(VpnInterface.class, VpnInterfaceKey.class);
181 String interfaceName = key.getName();
183 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface interfaceState =
184 InterfaceUtils.getInterfaceStateFromOperDS(broker, interfaceName);
185 if (interfaceState != null) {
186 // Interface state is up
187 processVpnInterfaceUp(InterfaceUtils.getDpIdFromInterface(interfaceState), interfaceName, interfaceState.getIfIndex());
189 LOG.trace("VPN interfaces are not yet operational.");
193 protected void processVpnInterfaceUp(BigInteger dpId, String interfaceName, int lPortTag) {
195 VpnInterface vpnInterface = VpnUtil.getConfiguredVpnInterface(broker, interfaceName);
196 if(vpnInterface == null) {
197 LOG.info("Unable to process add/up for interface {} as it is not configured", interfaceName);
200 String vpnName = vpnInterface.getVpnInstanceName();
201 LOG.info("Binding vpn service to interface {} ", interfaceName);
202 long vpnId = VpnUtil.getVpnId(broker, vpnName);
203 if (vpnId == VpnConstants.INVALID_ID) {
204 LOG.trace("VpnInstance to VPNId mapping is not yet available, bailing out now.");
207 synchronized (interfaceName.intern()) {
208 if (VpnUtil.getOperationalVpnInterface(broker, vpnInterface.getName()) != null) {
209 LOG.trace("VPN Interface already provisioned , bailing out from here.");
213 bindService(dpId, vpnName, interfaceName, lPortTag);
214 updateDpnDbs(vpnName, interfaceName, true);
215 processVpnInterfaceAdjacencies(VpnUtil.getVpnInterfaceIdentifier(vpnInterface.getName()), vpnInterface, true);
220 private void updateDpnDbs(String vpnName, String interfaceName, boolean add) {
221 long vpnId = VpnUtil.getVpnId(broker, vpnName);
222 BigInteger dpId = InterfaceUtils.getDpnForInterface(interfaceManager, interfaceName);
223 if(!dpId.equals(BigInteger.ZERO)) {
225 updateMappingDbs(vpnId, dpId, interfaceName, vpnName);
227 removeFromMappingDbs(vpnId, dpId, interfaceName, vpnName);
232 private void bindService(BigInteger dpId, String vpnInstanceName, String vpnInterfaceName, int lPortTag) {
233 int priority = VpnConstants.DEFAULT_FLOW_PRIORITY;
234 long vpnId = VpnUtil.getVpnId(broker, vpnInstanceName);
236 int instructionKey = 0;
237 List<Instruction> instructions = new ArrayList<Instruction>();
239 instructions.add(MDSALUtil.buildAndGetWriteMetadaInstruction(BigInteger.valueOf(vpnId), MetaDataUtil.METADATA_MASK_VRFID, ++instructionKey));
240 instructions.add(MDSALUtil.buildAndGetGotoTableInstruction(NwConstants.L3_FIB_TABLE, ++instructionKey));
244 InterfaceUtils.getBoundServices(String.format("%s.%s.%s", "vpn",vpnInstanceName, vpnInterfaceName),
245 VpnConstants.L3VPN_SERVICE_IDENTIFIER, priority,
246 VpnConstants.COOKIE_VM_INGRESS_TABLE, instructions);
247 VpnUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION,
248 InterfaceUtils.buildServiceId(vpnInterfaceName, VpnConstants.L3VPN_SERVICE_IDENTIFIER), serviceInfo);
249 makeArpFlow(dpId, VpnConstants.L3VPN_SERVICE_IDENTIFIER, lPortTag, vpnInterfaceName,
250 vpnId, ArpReplyOrRequest.REQUEST, NwConstants.ADD_FLOW);
254 private void processVpnInterfaceAdjacencies(final InstanceIdentifier<VpnInterface> identifier, VpnInterface intf,
255 boolean vpnInterfaceState) {
256 String intfName = intf.getName();
258 synchronized (intfName) {
260 InstanceIdentifier<Adjacencies> path = identifier.augmentation(Adjacencies.class);
261 Optional<Adjacencies> adjacencies = VpnUtil.read(broker, LogicalDatastoreType.CONFIGURATION, path);
263 if (adjacencies.isPresent()) {
264 List<Adjacency> nextHops = adjacencies.get().getAdjacency();
265 List<Adjacency> value = new ArrayList<>();
267 // Get the rd of the vpn instance
268 String rd = getRouteDistinguisher(intf.getVpnInstanceName());
270 BigInteger dpnId = InterfaceUtils.getDpnForInterface(interfaceManager, intfName);
271 String nextHopIp = InterfaceUtils.getEndpointIpAddressForDPN(broker, dpnId);
272 if (nextHopIp == null){
273 LOG.error("NextHop for interface {} is null", intfName);
276 LOG.trace("NextHops are {}", nextHops);
277 for (Adjacency nextHop : nextHops) {
278 String prefix = VpnUtil.getIpPrefix(nextHop.getIpAddress());
279 long label = VpnUtil.getUniqueId(idManager, VpnConstants.VPN_IDPOOL_NAME, VpnUtil
280 .getNextHopLabelKey((rd == null) ? intf.getVpnInstanceName() : rd, prefix));
281 String adjNextHop = nextHop.getNextHopIp();
282 value.add(new AdjacencyBuilder(nextHop).setLabel(label).setNextHopIp((adjNextHop != null && !adjNextHop.isEmpty()) ? adjNextHop : nextHopIp)
283 .setIpAddress(prefix).setKey(new AdjacencyKey(prefix)).build());
284 if(nextHop.getMacAddress() != null && !nextHop.getMacAddress().isEmpty()) {
287 LogicalDatastoreType.OPERATIONAL,
288 VpnUtil.getPrefixToInterfaceIdentifier(
289 VpnUtil.getVpnId(broker, intf.getVpnInstanceName()), prefix),
290 VpnUtil.getPrefixToInterface(dpnId, intf.getName(), prefix));
294 Adjacencies aug = VpnUtil.getVpnInterfaceAugmentation(value);
295 VpnInterface opInterface = VpnUtil.getVpnInterface(intfName, intf.getVpnInstanceName(),
296 aug, vpnInterfaceState);
297 InstanceIdentifier<VpnInterface> interfaceId = VpnUtil.getVpnInterfaceIdentifier(intfName);
298 VpnUtil.syncWrite(broker, LogicalDatastoreType.OPERATIONAL, interfaceId, opInterface);
299 for (Adjacency nextHop : aug.getAdjacency()) {
300 long label = nextHop.getLabel();
301 String adjNextHop = nextHop.getNextHopIp();
303 addPrefixToBGP(rd, nextHop.getIpAddress(),
304 (adjNextHop != null && !adjNextHop.isEmpty()) ? adjNextHop : nextHopIp, label);
306 // ### add FIB route directly
307 addFibEntryToDS(intf.getVpnInstanceName(), nextHop.getIpAddress(),
308 (adjNextHop != null && !adjNextHop.isEmpty()) ? adjNextHop : nextHopIp, (int) label);
315 private void makeArpFlow(BigInteger dpId,short sIndex, int lPortTag, String vpnInterfaceName,
316 long vpnId, ArpReplyOrRequest replyOrRequest, int addOrRemoveFlow){
317 List<MatchInfo> matches = new ArrayList<MatchInfo>();
318 BigInteger metadata = MetaDataUtil.getMetaDataForLPortDispatcher(lPortTag, ++sIndex, BigInteger.valueOf(vpnId));
319 BigInteger metadataMask = MetaDataUtil.getMetaDataMaskForLPortDispatcher(MetaDataUtil.METADATA_MASK_SERVICE_INDEX,
320 MetaDataUtil.METADATA_MASK_LPORT_TAG, MetaDataUtil.METADATA_MASK_VRFID);
322 // Matching Arp reply flows
323 matches.add(new MatchInfo(MatchFieldType.eth_type, new long[] { NwConstants.ETHTYPE_ARP }));
324 matches.add(new MatchInfo(MatchFieldType.metadata, new BigInteger[] {
325 metadata, metadataMask }));
327 matches.add(new MatchInfo(MatchFieldType.arp_op, new long[] { replyOrRequest.getArpOperation() }));
329 // Instruction to punt to controller
330 List<InstructionInfo> instructions = new ArrayList<InstructionInfo>();
331 List<ActionInfo> actionsInfos = new ArrayList<ActionInfo>();
332 actionsInfos.add(new ActionInfo(ActionType.punt_to_controller, new String[] {}));
333 instructions.add(new InstructionInfo(InstructionType.write_actions, actionsInfos));
335 // Install the flow entry in L3_INTERFACE_TABLE
336 String flowRef = VpnUtil.getFlowRef(dpId, NwConstants.L3_INTERFACE_TABLE,
337 NwConstants.ETHTYPE_ARP, lPortTag, replyOrRequest.getArpOperation());
338 FlowEntity flowEntity;
339 flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.L3_INTERFACE_TABLE, flowRef,
340 NwConstants.DEFAULT_ARP_FLOW_PRIORITY, replyOrRequest.getName(), 0, 0,
341 VpnUtil.getCookieArpFlow(lPortTag), matches, instructions);
343 if (addOrRemoveFlow == NwConstants.ADD_FLOW) {
344 LOG.debug("Creating ARP Flow for interface {}",vpnInterfaceName);
345 mdsalManager.installFlow(flowEntity);
347 LOG.debug("Deleting ARP Flow for interface {}",vpnInterfaceName);
348 mdsalManager.removeFlow(flowEntity);
352 private String getRouteDistinguisher(String vpnName) {
353 InstanceIdentifier<VpnInstance> id = InstanceIdentifier.builder(VpnInstances.class)
354 .child(VpnInstance.class, new VpnInstanceKey(vpnName)).build();
355 Optional<VpnInstance> vpnInstance = VpnUtil.read(broker, LogicalDatastoreType.CONFIGURATION, id);
357 if(vpnInstance.isPresent()) {
358 VpnInstance instance = vpnInstance.get();
359 VpnAfConfig config = instance.getIpv4Family();
360 rd = config.getRouteDistinguisher();
365 private synchronized void updateMappingDbs(long vpnId, BigInteger dpnId, String intfName, String vpnName) {
366 String routeDistinguisher = getRouteDistinguisher(vpnName);
367 String rd = (routeDistinguisher == null) ? vpnName : routeDistinguisher;
368 InstanceIdentifier<VpnToDpnList> id = VpnUtil.getVpnToDpnListIdentifier(rd, dpnId);
369 Optional<VpnToDpnList> dpnInVpn = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, id);
370 org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.vpn.to.dpn.list.VpnInterfaces
371 vpnInterface = new VpnInterfacesBuilder().setInterfaceName(intfName).build();
373 if (dpnInVpn.isPresent()) {
374 VpnUtil.syncWrite(broker, LogicalDatastoreType.OPERATIONAL, id.child(
375 org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.vpn.instance
376 .op.data.vpn.instance.op.data.entry.vpn.to.dpn.list.VpnInterfaces.class,
377 new VpnInterfacesKey(intfName)), vpnInterface);
379 VpnUtil.syncUpdate(broker, LogicalDatastoreType.OPERATIONAL,
380 VpnUtil.getVpnInstanceOpDataIdentifier(rd),
381 VpnUtil.getVpnInstanceOpDataBuilder(rd, vpnId));
382 VpnToDpnListBuilder vpnToDpnList = new VpnToDpnListBuilder().setDpnId(dpnId);
383 List<org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.vpn.instance.op.data
384 .vpn.instance.op.data.entry.vpn.to.dpn.list.VpnInterfaces> vpnInterfaces = new ArrayList<>();
385 vpnInterfaces.add(vpnInterface);
386 VpnUtil.syncWrite(broker, LogicalDatastoreType.OPERATIONAL, id,
387 vpnToDpnList.setVpnInterfaces(vpnInterfaces).build());
390 * FIXME: DC Gateway tunnel should be built dynamically
391 //this is the first VM in this VPN on the DPN, may be a new DPN has come up,
392 //if tunnel to DC GW does not exist, create it
393 //if(!tunnelExists(dpnID, bgpManager.getDCGWIP()))
394 String dcGW = bgpManager.getDCGwIP();
395 if(dcGW != null && !dcGW.isEmpty())
397 LOG.debug("Building tunnel from DPN {} to DC GW {}", dpnId, dcGW);
398 itmProvider.buildTunnelFromDPNToDCGW(dpnId, new IpAddress(dcGW.toCharArray()));
400 fibManager.populateFibOnNewDpn(dpnId, vpnId, (rd == null) ? vpnName : rd);
404 private synchronized void removeFromMappingDbs(long vpnId, BigInteger dpnId, String intfName, String vpnName) {
405 //TODO: Delay 'DPN' removal so that other services can cleanup the entries for this dpn
406 String rd = VpnUtil.getVpnRd(broker, vpnName);
407 InstanceIdentifier<VpnToDpnList> id = VpnUtil.getVpnToDpnListIdentifier(rd, dpnId);
408 Optional<VpnToDpnList> dpnInVpn = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, id);
409 if (dpnInVpn.isPresent()) {
410 List<org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.vpn.instance.op.data
411 .vpn.instance.op.data.entry.vpn.to.dpn.list.VpnInterfaces> vpnInterfaces = dpnInVpn.get().getVpnInterfaces();
412 org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.vpn.to.dpn.list.VpnInterfaces
413 currVpnInterface = new VpnInterfacesBuilder().setInterfaceName(intfName).build();
415 if (vpnInterfaces.remove(currVpnInterface)) {
416 if (vpnInterfaces.isEmpty()) {
417 VpnUtil.delete(broker, LogicalDatastoreType.OPERATIONAL, id, VpnUtil.DEFAULT_CALLBACK);
418 fibManager.cleanUpDpnForVpn(dpnId, vpnId, rd);
420 VpnUtil.delete(broker, LogicalDatastoreType.OPERATIONAL, id.child(
421 org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.vpn.instance.op.data
422 .vpn.instance.op.data.entry.vpn.to.dpn.list.VpnInterfaces.class,
423 new VpnInterfacesKey(intfName)), VpnUtil.DEFAULT_CALLBACK);
429 private void addPrefixToBGP(String rd, String prefix, String nextHopIp, long label) {
431 bgpManager.addPrefix(rd, prefix, nextHopIp, (int)label);
432 } catch(Exception e) {
433 LOG.error("Add prefix failed", e);
438 private InstanceIdentifier<VpnInterface> getWildCardPath() {
439 return InstanceIdentifier.create(VpnInterfaces.class).child(VpnInterface.class);
443 protected void remove( InstanceIdentifier<VpnInterface> identifier, VpnInterface vpnInterface) {
444 LOG.trace("Remove event - key: {}, value: {}" ,identifier, vpnInterface );
445 final VpnInterfaceKey key = identifier.firstKeyOf(VpnInterface.class, VpnInterfaceKey.class);
446 String interfaceName = key.getName();
448 InstanceIdentifier<VpnInterface> interfaceId = VpnUtil.getVpnInterfaceIdentifier(interfaceName);
449 Optional<VpnInterface> existingVpnInterface = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, interfaceId);
450 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface interfaceState =
451 InterfaceUtils.getInterfaceStateFromOperDS(broker, interfaceName);
453 if (existingVpnInterface.isPresent() && interfaceState != null) {
454 processVpnInterfaceDown(InterfaceUtils.getDpIdFromInterface(interfaceState), interfaceName, interfaceState.getIfIndex(), false);
456 LOG.warn("VPN interface {} was unavailable in operational data store to handle remove event", interfaceName);
460 protected void processVpnInterfaceDown(BigInteger dpId, String interfaceName, int lPortTag, boolean isInterfaceStateDown) {
461 VpnInterface vpnInterface = VpnUtil.getOperationalVpnInterface(broker, interfaceName);
462 if(vpnInterface == null) {
463 LOG.info("Unable to process delete/down for interface {} as it is not available in operational data store", interfaceName);
466 String vpnName = vpnInterface.getVpnInstanceName();
467 InstanceIdentifier<VpnInterface> identifier = VpnUtil.getVpnInterfaceIdentifier(interfaceName);
469 synchronized (interfaceName.intern()) {
470 removeAdjacenciesFromVpn(identifier, vpnInterface);
471 LOG.info("Unbinding vpn service from interface {} ", interfaceName);
472 unbindService(dpId, vpnName, interfaceName, lPortTag, isInterfaceStateDown);
474 //wait till DCN for removal of vpn interface in operational DS arrives
475 Runnable notifyTask = new VpnNotifyTask();
476 synchronized (interfaceName.intern()) {
477 vpnIntfMap.put(interfaceName, notifyTask);
478 synchronized (notifyTask) {
480 notifyTask.wait(VpnConstants.WAIT_TIME_IN_MILLISECONDS);
481 } catch (InterruptedException e) {
489 private void removeAdjacenciesFromVpn(final InstanceIdentifier<VpnInterface> identifier, VpnInterface intf) {
491 InstanceIdentifier<Adjacencies> path = identifier.augmentation(Adjacencies.class);
492 Optional<Adjacencies> adjacencies = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, path);
494 String rd = VpnUtil.getVpnRd(broker, intf.getVpnInstanceName());
495 if (adjacencies.isPresent()) {
496 VpnUtil.syncUpdate(broker, LogicalDatastoreType.OPERATIONAL, identifier.augmentation(OpState.class),
497 new OpStateBuilder().setStateUp(false).build());
498 List<Adjacency> nextHops = adjacencies.get().getAdjacency();
500 if (!nextHops.isEmpty()) {
501 LOG.trace("NextHops are " + nextHops);
502 for (Adjacency nextHop : nextHops) {
503 VpnUtil.releaseId(idManager, VpnConstants.VPN_IDPOOL_NAME,
504 VpnUtil.getNextHopLabelKey(rd, nextHop.getIpAddress()));
505 /*VpnUtil.delete(broker, LogicalDatastoreType.OPERATIONAL,
506 VpnUtil.getPrefixToInterfaceIdentifier(
507 VpnUtil.getVpnId(broker, intf.getVpnInstanceName()),
508 nextHop.getIpAddress()),
509 VpnUtil.DEFAULT_CALLBACK);*/
510 if (rd.equals(intf.getVpnInstanceName())) {
511 //this is an internal vpn - the rd is assigned to the vpn instance name;
512 //remove from FIB directly
513 removeFibEntryFromDS(intf.getVpnInstanceName(), nextHop.getIpAddress());
515 removePrefixFromBGP(rd, nextHop.getIpAddress());
523 private void unbindService(BigInteger dpId, String vpnInstanceName, String vpnInterfaceName,
524 int lPortTag, boolean isInterfaceStateDown) {
525 if (!isInterfaceStateDown) {
526 VpnUtil.delete(broker, LogicalDatastoreType.CONFIGURATION,
527 InterfaceUtils.buildServiceId(vpnInterfaceName,
528 VpnConstants.L3VPN_SERVICE_IDENTIFIER),
529 VpnUtil.DEFAULT_CALLBACK);
531 long vpnId = VpnUtil.getVpnId(broker, vpnInstanceName);
532 makeArpFlow(dpId, VpnConstants.L3VPN_SERVICE_IDENTIFIER, lPortTag, vpnInterfaceName,
533 vpnId, ArpReplyOrRequest.REQUEST, NwConstants.DEL_FLOW);
537 private void removePrefixFromBGP(String rd, String prefix) {
539 bgpManager.deletePrefix(rd, prefix);
540 } catch(Exception e) {
541 LOG.error("Delete prefix failed", e);
546 protected void update(InstanceIdentifier<VpnInterface> identifier,
547 VpnInterface original, VpnInterface update) {
548 LOG.trace("Update VPN Interface {} , original {}, update {}",
549 identifier, original, update);
550 String vpnName = original.getVpnInstanceName();
552 boolean vpnNameChanged = false;
553 String rd = getRouteDistinguisher(vpnName);
555 String newVpnName = update.getVpnInstanceName();
556 if(!vpnName.equals(newVpnName)) {
557 //VPN for this interface got changed.
558 //Remove the interface from old VPN and add it to new VPN
559 newRd = getRouteDistinguisher(newVpnName);
560 if(newRd.equals("")) {
561 LOG.warn("VPN Instance {} not found. Update operation aborted", newVpnName);
564 vpnNameChanged = true;
565 LOG.debug("New VPN Name for the interface {} is {}", newVpnName, original.getName());
568 List<Adjacency> oldAdjs = original.getAugmentation(Adjacencies.class).getAdjacency();
569 List<Adjacency> newAdjs = update.getAugmentation(Adjacencies.class).getAdjacency();
570 if(vpnNameChanged && newAdjs != null && !newAdjs.isEmpty()) {
571 long label = VpnConstants.INVALID_ID;
572 InstanceIdentifier<Adjacencies> path = identifier.augmentation(Adjacencies.class);
573 Optional<Adjacencies> adjacencies = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, path);
574 if (adjacencies.isPresent()) {
575 List<Adjacency> nextHops = adjacencies.get().getAdjacency();
576 for(Adjacency nextHop : nextHops) {
577 label = nextHop.getLabel();
578 if(label == VpnConstants.INVALID_ID) {
579 //Generate label using ID Manager
580 label = VpnUtil.getUniqueId(idManager, VpnConstants.VPN_IDPOOL_NAME,
581 VpnUtil.getNextHopLabelKey(newRd, nextHop.getIpAddress()));
584 removePrefixFromBGP(rd, nextHop.getIpAddress());
586 removeFibEntryFromDS(vpnName, nextHop.getIpAddress());
588 //updatePrefixToBGP(newRd, nextHop, nextHopIp, label);
590 processVpnInterfaceAdjacencies(identifier, update, true);
591 VpnUtil.syncUpdate(broker, LogicalDatastoreType.OPERATIONAL, identifier, update);
593 } else if (oldAdjs != newAdjs) {
594 //handle both addition and removal of adjacencies
595 //currently, new adjacency may be an extra route
596 for (Adjacency adj : newAdjs) {
597 if (oldAdjs.contains(adj)) {
600 // add new adjacency - right now only extra route will hit this path
601 addNewAdjToVpnInterface(identifier, adj);
605 for (Adjacency adj : oldAdjs) {
606 delAdjFromVpnInterface(identifier, adj);
610 LOG.debug("No Update information is available for VPN Interface to proceed");
615 public void processArpRequest(IpAddress srcIP, PhysAddress srcMac, IpAddress targetIP, String srcInterface){
616 SendArpResponseInput input = new SendArpResponseInputBuilder().setInterface(srcInterface)
617 .setIpaddress(srcIP).setSrcIpAddress(targetIP).setMacaddress(srcMac).build();
618 final String msgFormat = String.format("Send ARP Response on interface %s to destination %s", srcInterface, srcIP);
619 Future<RpcResult<Void>> future = arpManager.sendArpResponse(input);
620 Futures.addCallback(JdkFutureAdapters.listenInPoolThread(future), new FutureCallback<RpcResult<Void>>() {
622 public void onFailure(Throwable error) {
623 LOG.error("Error - {}", msgFormat, error);
627 public void onSuccess(RpcResult<Void> result) {
628 if(!result.isSuccessful()) {
629 LOG.warn("Rpc call to {} failed", msgFormat, getErrorText(result.getErrors()));
631 LOG.debug("Successful RPC Result - {}", msgFormat);
637 private String getErrorText(Collection<RpcError> errors) {
638 StringBuilder errorText = new StringBuilder();
639 for(RpcError error : errors) {
640 errorText.append(",").append(error.getErrorType()).append("-")
641 .append(error.getMessage());
643 return errorText.toString();
646 private String getTunnelInterfaceFlowRef(BigInteger dpnId, short tableId, String ifName) {
647 return new StringBuilder().append(dpnId).append(tableId).append(ifName).toString();
652 public synchronized void addFibEntryToDS(String rd, String prefix,
653 String nexthop, int label) {
655 VrfEntry vrfEntry = new VrfEntryBuilder().setDestPrefix(prefix).
656 setNextHopAddress(nexthop).setLabel((long)label).build();
657 LOG.debug("Created vrfEntry for {} nexthop {} label {}", prefix, nexthop, label);
659 List<VrfEntry> vrfEntryList = new ArrayList<VrfEntry>();
660 vrfEntryList.add(vrfEntry);
662 InstanceIdentifierBuilder<VrfTables> idBuilder =
663 InstanceIdentifier.builder(FibEntries.class).child(VrfTables.class, new VrfTablesKey(rd));
664 InstanceIdentifier<VrfTables> vrfTableId = idBuilder.build();
666 VrfTables vrfTableNew = new VrfTablesBuilder().setRouteDistinguisher(rd).
667 setVrfEntry(vrfEntryList).build();
669 VpnUtil.syncUpdate(broker, LogicalDatastoreType.CONFIGURATION, vrfTableId, vrfTableNew);
672 public synchronized void removeFibEntryFromDS(String rd, String prefix) {
674 LOG.debug("Removing fib entry with destination prefix {} from vrf table for rd {}", prefix, rd);
676 InstanceIdentifierBuilder<VrfEntry> idBuilder =
677 InstanceIdentifier.builder(FibEntries.class).child(VrfTables.class, new VrfTablesKey(rd)).child(VrfEntry.class, new VrfEntryKey(prefix));
678 InstanceIdentifier<VrfEntry> vrfEntryId = idBuilder.build();
679 VpnUtil.delete(broker, LogicalDatastoreType.CONFIGURATION, vrfEntryId, VpnUtil.DEFAULT_CALLBACK);
683 public synchronized void removeVrfFromDS(String rd) {
684 LOG.debug("Removing vrf table for rd {}", rd);
686 InstanceIdentifierBuilder<VrfTables> idBuilder =
687 InstanceIdentifier.builder(FibEntries.class).child(VrfTables.class, new VrfTablesKey(rd));
688 InstanceIdentifier<VrfTables> vrfTableId = idBuilder.build();
690 VpnUtil.delete(broker, LogicalDatastoreType.CONFIGURATION, vrfTableId, VpnUtil.DEFAULT_CALLBACK);
694 protected void addNewAdjToVpnInterface(InstanceIdentifier<VpnInterface> identifier, Adjacency adj) {
696 Optional<VpnInterface> optVpnInterface = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, identifier);
698 if (optVpnInterface.isPresent()) {
699 VpnInterface currVpnIntf = optVpnInterface.get();
700 String prefix = VpnUtil.getIpPrefix(adj.getIpAddress());
701 String rd = getRouteDistinguisher(currVpnIntf.getVpnInstanceName());
702 InstanceIdentifier<Adjacencies> adjPath = identifier.augmentation(Adjacencies.class);
703 Optional<Adjacencies> optAdjacencies = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, adjPath);
705 VpnUtil.getUniqueId(idManager, VpnConstants.VPN_IDPOOL_NAME,
706 VpnUtil.getNextHopLabelKey((rd != null) ? rd : currVpnIntf.getVpnInstanceName(), prefix));
708 List<Adjacency> adjacencies;
709 if (optAdjacencies.isPresent()) {
710 adjacencies = optAdjacencies.get().getAdjacency();
712 //This code will not be hit since VM adjacency will always be there
713 adjacencies = new ArrayList<>();
716 adjacencies.add(new AdjacencyBuilder(adj).setLabel(label).setNextHopIp(adj.getNextHopIp())
717 .setIpAddress(prefix).setKey(new AdjacencyKey(prefix)).build());
719 Adjacencies aug = VpnUtil.getVpnInterfaceAugmentation(adjacencies);
720 VpnInterface newVpnIntf = VpnUtil.getVpnInterface(currVpnIntf.getName(), currVpnIntf.getVpnInstanceName(),
721 aug, currVpnIntf.getAugmentation(OpState.class).isStateUp());
723 VpnUtil.syncUpdate(broker, LogicalDatastoreType.OPERATIONAL, identifier, newVpnIntf);
724 addExtraRoute(adj.getIpAddress(), adj.getNextHopIp(), rd, currVpnIntf.getVpnInstanceName(), (int) label, currVpnIntf.getName());
730 protected void delAdjFromVpnInterface(InstanceIdentifier<VpnInterface> identifier, Adjacency adj) {
731 Optional<VpnInterface> optVpnInterface = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, identifier);
733 if (optVpnInterface.isPresent()) {
734 VpnInterface currVpnIntf = optVpnInterface.get();
736 InstanceIdentifier<Adjacencies> path = identifier.augmentation(Adjacencies.class);
737 Optional<Adjacencies> optAdjacencies = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, path);
738 if (optAdjacencies.isPresent()) {
739 List<Adjacency> adjacencies = optAdjacencies.get().getAdjacency();
741 if (!adjacencies.isEmpty()) {
742 String rd = getRouteDistinguisher(currVpnIntf.getVpnInstanceName());
743 LOG.trace("Adjacencies are " + adjacencies);
744 Iterator<Adjacency> adjIt = adjacencies.iterator();
745 while (adjIt.hasNext()) {
746 Adjacency adjElem = adjIt.next();
747 if (adjElem.getIpAddress().equals(adj.getIpAddress())) {
748 VpnUtil.releaseId(idManager, VpnConstants.VPN_IDPOOL_NAME,
749 VpnUtil.getNextHopLabelKey(rd, adj.getIpAddress()));
752 Adjacencies aug = VpnUtil.getVpnInterfaceAugmentation(adjacencies);
753 VpnInterface newVpnIntf = VpnUtil.getVpnInterface(currVpnIntf.getName(),
754 currVpnIntf.getVpnInstanceName(),
756 currVpnIntf.getAugmentation(OpState.class).isStateUp());
758 VpnUtil.syncUpdate(broker, LogicalDatastoreType.OPERATIONAL, identifier, newVpnIntf);
760 delExtraRoute(adj.getIpAddress(), rd, currVpnIntf.getVpnInstanceName());
771 protected void addExtraRoute(String destination, String nextHop, String rd, String routerID, int label, String intfName) {
773 //add extra route to vpn mapping; advertise with nexthop as tunnel ip
776 LogicalDatastoreType.OPERATIONAL,
777 VpnUtil.getVpnToExtrarouteIdentifier(
778 (rd != null) ? rd : routerID, destination),
779 VpnUtil.getVpnToExtraroute(destination, nextHop));
781 if(intfName != null && !intfName.isEmpty()) {
782 BigInteger dpnId = InterfaceUtils.getDpnForInterface(interfaceManager, intfName);
783 String nextHopIp = InterfaceUtils.getEndpointIpAddressForDPN(broker, dpnId);
784 if (nextHopIp == null && !nextHopIp.isEmpty()) {
785 LOG.error("NextHop for interface {} is null. Failed adding extra route for prefix {}", intfName, destination);
791 addPrefixToBGP(rd, destination, nextHop, label);
793 // ### add FIB route directly
794 addFibEntryToDS(routerID, destination, nextHop, label);
798 protected void delExtraRoute(String destination, String rd, String routerID) {
800 removePrefixFromBGP(rd, destination);
802 // ### add FIB route directly
803 removeFibEntryFromDS(routerID, destination);
807 class VpnInterfaceOpListener extends org.opendaylight.vpnservice.mdsalutil.AbstractDataChangeListener<VpnInterface> {
809 public VpnInterfaceOpListener() {
810 super(VpnInterface.class);
814 protected void remove(InstanceIdentifier<VpnInterface> identifier, VpnInterface del) {
815 final VpnInterfaceKey key = identifier.firstKeyOf(VpnInterface.class, VpnInterfaceKey.class);
816 String interfaceName = key.getName();
818 //increment the vpn interface count in Vpn Instance Op Data
820 String rd = getRouteDistinguisher(del.getVpnInstanceName());
821 if(rd.isEmpty()) rd = del.getVpnInstanceName();
822 VpnInstanceOpDataEntry vpnInstOp = VpnUtil.getVpnInstanceOpData(broker, rd);
823 if(vpnInstOp != null && vpnInstOp.getVpnInterfaceCount() != null) {
824 ifCnt = vpnInstOp.getVpnInterfaceCount();
827 LOG.trace("VpnInterfaceOpListener remove: interface name {} rd {} interface count in Vpn Op Instance {}", interfaceName, rd, ifCnt);
829 VpnUtil.asyncUpdate(broker, LogicalDatastoreType.OPERATIONAL,
830 VpnUtil.getVpnInstanceOpDataIdentifier(rd),
831 VpnUtil.updateIntfCntInVpnInstOpData(ifCnt - 1, rd), VpnUtil.DEFAULT_CALLBACK);
833 //TODO: Clean up the DPN List in Vpn Instance Op if ifCnt is zero
835 notifyTaskIfRequired(interfaceName);
838 private void notifyTaskIfRequired(String intfName) {
839 Runnable notifyTask = vpnIntfMap.remove(intfName);
840 if (notifyTask == null) {
843 executorService.execute(notifyTask);
847 protected void update(InstanceIdentifier<VpnInterface> identifier, VpnInterface original, VpnInterface update) {
851 protected void add(InstanceIdentifier<VpnInterface> identifier, VpnInterface add) {
852 final VpnInterfaceKey key = identifier.firstKeyOf(VpnInterface.class, VpnInterfaceKey.class);
853 String interfaceName = key.getName();
855 //increment the vpn interface count in Vpn Instance Op Data
857 String rd = getRouteDistinguisher(add.getVpnInstanceName());
858 if(rd.isEmpty()) rd = add.getVpnInstanceName();
859 VpnInstanceOpDataEntry vpnInstOp = VpnUtil.getVpnInstanceOpData(broker, rd);
860 if(vpnInstOp != null && vpnInstOp.getVpnInterfaceCount() != null) {
861 ifCnt = vpnInstOp.getVpnInterfaceCount();
864 LOG.trace("VpnInterfaceOpListener add: interface name {} rd {} interface count in Vpn Op Instance {}", interfaceName, rd, ifCnt);
866 VpnUtil.asyncUpdate(broker, LogicalDatastoreType.OPERATIONAL,
867 VpnUtil.getVpnInstanceOpDataIdentifier(rd),
868 VpnUtil.updateIntfCntInVpnInstOpData(ifCnt + 1, rd), VpnUtil.DEFAULT_CALLBACK);
874 protected void updatePrefixesForDPN(BigInteger dpnId, UpdateRouteAction action) {
876 LOG.info("Tunnel event triggered {} for Dpn:{} ", action.name(), dpnId);
877 InstanceIdentifierBuilder<VpnInstances> idBuilder = InstanceIdentifier.builder(VpnInstances.class);
878 InstanceIdentifier<VpnInstances> vpnInstancesId = idBuilder.build();
879 Optional<VpnInstances> vpnInstances = VpnUtil.read(broker, LogicalDatastoreType.CONFIGURATION, vpnInstancesId);
881 if (vpnInstances.isPresent()) {
882 List<VpnInstance> vpnInstanceList = vpnInstances.get().getVpnInstance();
883 Iterator<VpnInstance> vpnInstIter = vpnInstanceList.iterator();
884 while (vpnInstIter.hasNext()) {
885 VpnInstance vpnInstance = vpnInstIter.next();
886 VpnAfConfig vpnConfig = vpnInstance.getIpv4Family();
887 String rd = vpnConfig.getRouteDistinguisher();
889 InstanceIdentifier<VpnToDpnList> id = VpnUtil.getVpnToDpnListIdentifier(rd, dpnId);
890 Optional<VpnToDpnList> dpnInVpn = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, id);
891 if (dpnInVpn.isPresent()) {
892 if (action == UpdateRouteAction.ADVERTISE_ROUTE) {
893 fibManager.populateFibOnNewDpn(dpnId, VpnUtil
894 .getVpnId(broker, vpnInstance.getVpnInstanceName()), rd);
896 List<org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.vpn.instance.op.data
897 .vpn.instance.op.data.entry.vpn.to.dpn.list.VpnInterfaces> vpnInterfaces = dpnInVpn.get().getVpnInterfaces();
898 for(org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.vpn.instance.op.data
899 .vpn.instance.op.data.entry.vpn.to.dpn.list.VpnInterfaces vpnInterface : vpnInterfaces) {
900 InstanceIdentifier<VpnInterface> vpnIntfId = VpnUtil.getVpnInterfaceIdentifier(vpnInterface.getInterfaceName());
901 InstanceIdentifier<Adjacencies> path = vpnIntfId.augmentation(Adjacencies.class);
902 Optional<Adjacencies> adjacencies = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, path);
904 if (adjacencies.isPresent()) {
905 List<Adjacency> adjacencyList = adjacencies.get().getAdjacency();
906 Iterator<Adjacency> adjacencyIterator = adjacencyList.iterator();
908 while (adjacencyIterator.hasNext()) {
909 Adjacency adjacency = adjacencyIterator.next();
911 if(action == UpdateRouteAction.ADVERTISE_ROUTE)
912 bgpManager.addPrefix(rd, adjacency.getIpAddress(), adjacency.getNextHopIp(), adjacency.getLabel().intValue());
913 else if(action == UpdateRouteAction.WITHDRAW_ROUTE)
914 bgpManager.deletePrefix(rd, adjacency.getIpAddress());
915 } catch (Exception e) {
916 LOG.error("Exception when updating prefix {} in vrf {} to BGP", adjacency.getIpAddress(), rd);
922 if (action == UpdateRouteAction.WITHDRAW_ROUTE) {
923 fibManager.cleanUpDpnForVpn(dpnId, VpnUtil
924 .getVpnId(broker, vpnInstance.getVpnInstanceName()), rd);