2 * Copyright (c) 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
9 package org.opendaylight.netvirt.elan.internal;
11 import java.util.ArrayList;
12 import java.util.Collection;
13 import java.util.List;
14 import java.util.concurrent.Future;
16 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
17 import org.opendaylight.controller.md.sal.binding.api.NotificationService;
18 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
19 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
20 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
21 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
22 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
23 import org.opendaylight.netvirt.elan.utils.ElanForwardingEntriesHandler;
24 import org.opendaylight.netvirt.elanmanager.api.IElanService;
25 import org.opendaylight.netvirt.elanmanager.exceptions.MacNotFoundException;
26 import org.opendaylight.genius.datastoreutils.DataStoreJobCoordinator;
27 import org.opendaylight.netvirt.elan.l2gw.internal.ElanL2GatewayProvider;
28 import org.opendaylight.netvirt.elan.statisitcs.ElanStatisticsImpl;
29 import org.opendaylight.netvirt.elan.statusanddiag.ElanStatusMonitor;
30 import org.opendaylight.netvirt.elan.utils.ElanClusterUtils;
31 import org.opendaylight.netvirt.elan.utils.ElanConstants;
32 import org.opendaylight.netvirt.elan.utils.ElanUtils;
33 import org.opendaylight.genius.interfacemanager.exceptions.InterfaceAlreadyExistsException;
34 import org.opendaylight.genius.interfacemanager.globals.IfmConstants;
35 import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
36 import org.opendaylight.genius.itm.api.IITMProvider;
37 import org.opendaylight.genius.mdsalutil.MDSALUtil;
38 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
39 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanInstances;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanInterfaces;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan._interface.forwarding.entries.ElanInterfaceMac;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstanceBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstanceKey;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.ElanInterface;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.ElanInterfaceBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.ElanInterfaceKey;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.state.Elan;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.forwarding.entries.MacEntry;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.statistics.rev150824.ElanStatisticsService;
52 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.CreateIdPoolInput;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.CreateIdPoolInputBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfL2vlan;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.OdlInterfaceRpcService;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.ItmRpcService;
59 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
60 import org.opendaylight.yangtools.yang.common.RpcResult;
61 import org.slf4j.Logger;
62 import org.slf4j.LoggerFactory;
64 import com.google.common.base.Optional;
67 public class ElanServiceProvider implements BindingAwareProvider, IElanService, AutoCloseable {
69 private IdManagerService idManager;
70 private IMdsalApiManager mdsalManager;
71 private IInterfaceManager interfaceManager;
72 private OdlInterfaceRpcService interfaceManagerRpcService;
73 private ElanInstanceManager elanInstanceManager;
74 private ElanForwardingEntriesHandler elanForwardingEntriesHandler;
75 private ElanBridgeManager bridgeMgr;
77 public IdManagerService getIdManager() {
81 public ElanForwardingEntriesHandler getElanForwardingEntriesHandler() {
82 return elanForwardingEntriesHandler;
85 public ElanPacketInHandler getElanPacketInHandler() {
86 return elanPacketInHandler;
89 public ElanSmacFlowEventListener getElanSmacFlowEventListener() {
90 return elanSmacFlowEventListener;
93 public ElanInterfaceStateChangeListener getElanInterfaceStateChangeListener() {
94 return elanInterfaceStateChangeListener;
97 public ElanInterfaceStateClusteredListener getInfStateChangeClusteredListener() {
98 return infStateChangeClusteredListener;
101 public ElanDpnInterfaceClusteredListener getElanDpnInterfaceClusteredListener() {
102 return elanDpnInterfaceClusteredListener;
105 public ElanNodeListener getElanNodeListener() {
106 return elanNodeListener;
109 public NotificationService getNotificationService() {
110 return notificationService;
113 public RpcProviderRegistry getRpcProviderRegistry() {
114 return rpcProviderRegistry;
117 public ElanL2GatewayProvider getElanL2GatewayProvider() {
118 return elanL2GatewayProvider;
121 public static ElanStatusMonitor getElanstatusmonitor() {
122 return elanStatusMonitor;
125 public ElanItmEventListener getElanItmEventListener() {
126 return elanItmEventListener;
129 public static Logger getLogger() {
133 private ElanInterfaceManager elanInterfaceManager;
134 private ElanPacketInHandler elanPacketInHandler;
135 private ElanSmacFlowEventListener elanSmacFlowEventListener;
136 private ElanInterfaceStateChangeListener elanInterfaceStateChangeListener;
137 private ElanInterfaceStateClusteredListener infStateChangeClusteredListener;
138 private ElanDpnInterfaceClusteredListener elanDpnInterfaceClusteredListener;
139 private ElanNodeListener elanNodeListener;
140 private NotificationService notificationService;
141 private RpcProviderRegistry rpcProviderRegistry;
142 private IITMProvider itmManager;
143 private ItmRpcService itmRpcService;
144 private DataBroker broker;
145 private ElanL2GatewayProvider elanL2GatewayProvider;
146 private ElanStatisticsService interfaceStatsService;
147 private EntityOwnershipService entityOwnershipService;
148 private static final ElanStatusMonitor elanStatusMonitor = ElanStatusMonitor.getInstance();
149 static DataStoreJobCoordinator dataStoreJobCoordinator;
150 private ElanOvsdbNodeListener elanOvsdbNodeListener;
152 private boolean generateIntBridgeMac = true;
154 public static void setDataStoreJobCoordinator(DataStoreJobCoordinator ds) {
155 dataStoreJobCoordinator = ds;
158 public void setBroker(DataBroker broker) {
159 this.broker = broker;
162 public static DataStoreJobCoordinator getDataStoreJobCoordinator() {
163 if (dataStoreJobCoordinator == null) {
164 dataStoreJobCoordinator = DataStoreJobCoordinator.getInstance();
166 return dataStoreJobCoordinator;
170 public ElanServiceProvider(RpcProviderRegistry rpcRegistry) {
171 rpcProviderRegistry = rpcRegistry;
172 elanStatusMonitor.registerMbean();
175 // private ElanInterfaceStateChangeListener elanInterfaceEventListener;
176 private ElanItmEventListener elanItmEventListener;
178 private static final Logger logger = LoggerFactory.getLogger(ElanServiceProvider.class);
181 public void onSessionInitiated(ProviderContext session) {
182 elanStatusMonitor.reportStatus("STARTING");
185 getDataStoreJobCoordinator();
186 broker = session.getSALService(DataBroker.class);
188 bridgeMgr = new ElanBridgeManager(broker);
189 elanOvsdbNodeListener = new ElanOvsdbNodeListener(broker, generateIntBridgeMac, bridgeMgr, this);
190 ElanUtils.setElanServiceProvider(this);
191 elanForwardingEntriesHandler = ElanForwardingEntriesHandler.getElanForwardingEntriesHandler(this);
192 elanInterfaceManager = ElanInterfaceManager.getElanInterfaceManager(this);
193 elanInstanceManager = ElanInstanceManager.getElanInstanceManager(this);
194 elanNodeListener = ElanNodeListener.getElanNodeListener(this);
195 elanPacketInHandler = ElanPacketInHandler.getElanPacketInHandler(this);
196 elanSmacFlowEventListener = ElanSmacFlowEventListener.getElanSmacFlowEventListener(this);
197 // Initialize statistics rpc provider for elan
198 interfaceStatsService = ElanStatisticsImpl.getElanStatisticsService(this);
199 rpcProviderRegistry.addRpcImplementation(ElanStatisticsService.class, interfaceStatsService);
200 elanInterfaceStateChangeListener = ElanInterfaceStateChangeListener.getElanInterfaceStateChangeListener(this);
201 infStateChangeClusteredListener = ElanInterfaceStateClusteredListener.getElanInterfaceStateClusteredListener(this);
202 elanDpnInterfaceClusteredListener = ElanDpnInterfaceClusteredListener.getElanDpnInterfaceClusteredListener(this);
203 ElanClusterUtils.setElanServiceProvider(this);
204 this.elanL2GatewayProvider = new ElanL2GatewayProvider(this);
205 elanInterfaceManager.registerListener(LogicalDatastoreType.CONFIGURATION,broker);
206 elanInstanceManager.registerListener(LogicalDatastoreType.CONFIGURATION,broker);
207 notificationService.registerNotificationListener(elanSmacFlowEventListener);
208 notificationService.registerNotificationListener(elanPacketInHandler);
209 elanStatusMonitor.reportStatus("OPERATIONAL");
210 } catch (Exception e) {
211 logger.error("Error initializing services", e);
212 elanStatusMonitor.reportStatus("ERROR");
218 public void setIdManager(IdManagerService idManager) {
219 this.idManager = idManager;
222 public void setMdsalManager(IMdsalApiManager mdsalManager) {
223 this.mdsalManager = mdsalManager;
226 public void setInterfaceManager(IInterfaceManager interfaceManager) {
227 this.interfaceManager = interfaceManager;
230 public void setEntityOwnershipService(EntityOwnershipService entityOwnershipService) {
231 this.entityOwnershipService = entityOwnershipService;
234 public IInterfaceManager getInterfaceManager() {
235 return this.interfaceManager;
238 public IMdsalApiManager getMdsalManager() {
242 public IITMProvider getItmManager() {
246 public DataBroker getBroker() {
250 public void setNotificationService(NotificationService notificationService) {
251 this.notificationService = notificationService;
254 public void setInterfaceManagerRpcService(OdlInterfaceRpcService interfaceManager) {
255 this.interfaceManagerRpcService = interfaceManager;
258 public OdlInterfaceRpcService getInterfaceManagerRpcService() {
259 return interfaceManagerRpcService;
262 public void setItmManager(IITMProvider itmManager) {
263 this.itmManager = itmManager;
266 public void setItmRpcService(ItmRpcService itmRpcService) {
267 this.itmRpcService = itmRpcService;
270 public ItmRpcService getItmRpcService() {
271 return itmRpcService;
274 public ElanInstanceManager getElanInstanceManager() {
275 return elanInstanceManager;
278 public ElanInterfaceManager getElanInterfaceManager() {
279 return elanInterfaceManager;
282 public EntityOwnershipService getEntityOwnershipService() {
283 return entityOwnershipService;
286 private void createIdPool() {
287 CreateIdPoolInput createPool = new CreateIdPoolInputBuilder().setPoolName(ElanConstants.ELAN_ID_POOL_NAME)
288 .setLow(ElanConstants.ELAN_ID_LOW_VALUE).setHigh(ElanConstants.ELAN_ID_HIGH_VALUE).build();
290 Future<RpcResult<Void>> result = idManager.createIdPool(createPool);
291 if ((result != null) && (result.get().isSuccessful())) {
292 logger.debug("ELAN Id Pool is created successfully");
294 } catch (Exception e) {
295 logger.error("Failed to create ELAN Id pool {}", e);
300 public boolean createElanInstance(String elanInstanceName, long macTimeout, String description) {
301 ElanInstance existingElanInstance = elanInstanceManager.getElanInstanceByName(elanInstanceName);
302 boolean isSuccess = true;
303 if (existingElanInstance != null) {
304 if (compareWithExistingElanInstance(existingElanInstance, macTimeout, description)) {
305 logger.debug("Elan Instance is already present in the Operational DS {}", existingElanInstance);
308 ElanInstance updateElanInstance = new ElanInstanceBuilder().setElanInstanceName(elanInstanceName)
309 .setDescription(description).setMacTimeout(macTimeout)
310 .setKey(new ElanInstanceKey(elanInstanceName)).build();
311 MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION,
312 ElanUtils.getElanInstanceConfigurationDataPath(elanInstanceName), updateElanInstance);
313 logger.debug("Updating the Elan Instance {} with MAC TIME-OUT %l and Description %s ",
314 updateElanInstance, macTimeout, description);
317 ElanInstance elanInstance = new ElanInstanceBuilder().setElanInstanceName(elanInstanceName)
318 .setMacTimeout(macTimeout).setDescription(description).setKey(new ElanInstanceKey(elanInstanceName))
320 MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION,
321 ElanUtils.getElanInstanceConfigurationDataPath(elanInstanceName), elanInstance);
322 logger.debug("Creating the new Elan Instance {}", elanInstance);
327 public static boolean compareWithExistingElanInstance(ElanInstance existingElanInstance, long macTimeOut,
328 String description) {
329 boolean isEqual = false;
330 if (existingElanInstance.getMacTimeout() == macTimeOut
331 && existingElanInstance.getDescription().equals(description)) {
338 public void updateElanInstance(String elanInstanceName, long newMacTimout, String newDescription) {
339 createElanInstance(elanInstanceName, newMacTimout, newDescription);
343 public boolean deleteElanInstance(String elanInstanceName) {
344 boolean isSuccess = false;
345 ElanInstance existingElanInstance = elanInstanceManager.getElanInstanceByName(elanInstanceName);
346 if (existingElanInstance == null) {
347 logger.debug("Elan Instance is not present {}", existingElanInstance);
350 logger.debug("Deletion of the existing Elan Instance {}", existingElanInstance);
351 ElanUtils.delete(broker, LogicalDatastoreType.CONFIGURATION,
352 ElanUtils.getElanInstanceConfigurationDataPath(elanInstanceName));
358 public void addElanInterface(String elanInstanceName, String interfaceName, List<String> staticMacAddresses,
359 String description) {
360 ElanInstance existingElanInstance = elanInstanceManager.getElanInstanceByName(elanInstanceName);
361 if (existingElanInstance != null) {
362 ElanInterface elanInterface;
363 if (staticMacAddresses == null) {
364 elanInterface = new ElanInterfaceBuilder().setElanInstanceName(elanInstanceName)
365 .setDescription(description).setName(interfaceName).setKey(new ElanInterfaceKey(interfaceName))
368 elanInterface = new ElanInterfaceBuilder().setElanInstanceName(elanInstanceName)
369 .setDescription(description).setName(interfaceName)
370 .setStaticMacEntries(getPhysAddress(staticMacAddresses))
371 .setKey(new ElanInterfaceKey(interfaceName)).build();
373 MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION,
374 ElanUtils.getElanInterfaceConfigurationDataPathId(interfaceName), elanInterface);
375 logger.debug("Creating the new ELan Interface {}", elanInterface);
381 public void updateElanInterface(String elanInstanceName, String interfaceName,
382 List<String> updatedStaticMacAddresses, String newDescription) {
383 ElanInterface existingElanInterface = ElanUtils.getElanInterfaceByElanInterfaceName(interfaceName);
384 if (existingElanInterface == null) {
387 List<PhysAddress> existingMacAddress = existingElanInterface.getStaticMacEntries();
388 List<PhysAddress> updatedMacAddresses = getPhysAddress(updatedStaticMacAddresses);
389 List<PhysAddress> updatedPhysAddress = getUpdatedPhyAddress(existingMacAddress, updatedMacAddresses);
390 if (updatedPhysAddress.size() > 0) {
391 logger.debug("updating the ElanInterface with new Mac Entries {}", updatedStaticMacAddresses);
392 ElanInterface elanInterface = new ElanInterfaceBuilder().setElanInstanceName(elanInstanceName)
393 .setName(interfaceName).setDescription(newDescription).setStaticMacEntries(updatedPhysAddress)
394 .setKey(new ElanInterfaceKey(interfaceName)).build();
395 MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION,
396 ElanUtils.getElanInterfaceConfigurationDataPathId(interfaceName), elanInterface);
401 public void deleteElanInterface(String elanInstanceName, String interfaceName) {
402 ElanInterface existingElanInterface = ElanUtils.getElanInterfaceByElanInterfaceName(interfaceName);
403 if (existingElanInterface != null) {
404 ElanUtils.delete(broker, LogicalDatastoreType.CONFIGURATION,
405 ElanUtils.getElanInterfaceConfigurationDataPathId(interfaceName));
406 logger.debug("deleting the Elan Interface {}", existingElanInterface);
411 public void addStaticMacAddress(String elanInstanceName, String interfaceName, String macAddress) {
412 ElanInterface existingElanInterface = ElanUtils.getElanInterfaceByElanInterfaceName(interfaceName);
413 PhysAddress updateStaticMacAddress = new PhysAddress(macAddress);
414 if (existingElanInterface != null) {
415 List<PhysAddress> existingMacAddress = existingElanInterface.getStaticMacEntries();
416 if (existingMacAddress.contains(updateStaticMacAddress)) {
419 existingMacAddress.add(updateStaticMacAddress);
420 ElanInterface elanInterface = new ElanInterfaceBuilder().setElanInstanceName(elanInstanceName)
421 .setName(interfaceName).setStaticMacEntries(existingMacAddress)
422 .setDescription(existingElanInterface.getDescription()).setKey(new ElanInterfaceKey(interfaceName))
424 MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION,
425 ElanUtils.getElanInterfaceConfigurationDataPathId(interfaceName), elanInterface);
430 public void deleteStaticMacAddress(String elanInstanceName, String interfaceName, String macAddress)
431 throws MacNotFoundException {
432 ElanInterface existingElanInterface = ElanUtils.getElanInterfaceByElanInterfaceName(interfaceName);
433 PhysAddress physAddress = new PhysAddress(macAddress);
434 if (existingElanInterface == null) {
437 List<PhysAddress> existingMacAddress = existingElanInterface.getStaticMacEntries();
438 if (existingMacAddress.contains(physAddress)) {
439 existingMacAddress.remove(physAddress);
440 ElanInterface elanInterface = new ElanInterfaceBuilder().setElanInstanceName(elanInstanceName)
441 .setName(interfaceName).setStaticMacEntries(existingMacAddress)
442 .setDescription(existingElanInterface.getDescription()).setKey(new ElanInterfaceKey(interfaceName))
444 MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION,
445 ElanUtils.getElanInterfaceConfigurationDataPathId(interfaceName), elanInterface);
447 throw new MacNotFoundException("Mac Not Found Exception");
452 public Collection<MacEntry> getElanMacTable(String elanInstanceName) {
453 Elan elanInfo = ElanUtils.getElanByName(elanInstanceName);
454 List<MacEntry> macAddress = new ArrayList<>();
455 if (elanInfo == null) {
458 List<String> elanInterfaces = elanInfo.getElanInterfaces();
459 if (elanInterfaces != null && elanInterfaces.size() > 0) {
460 for (String elanInterface : elanInterfaces) {
461 ElanInterfaceMac elanInterfaceMac = ElanUtils.getElanInterfaceMacByInterfaceName(elanInterface);
462 if (elanInterfaceMac != null && elanInterfaceMac.getMacEntry() != null
463 && elanInterfaceMac.getMacEntry().size() > 0) {
464 macAddress.addAll(elanInterfaceMac.getMacEntry());
472 public void flushMACTable(String elanInstanceName) {
473 Elan elanInfo = ElanUtils.getElanByName(elanInstanceName);
474 if (elanInfo == null) {
477 List<String> elanInterfaces = elanInfo.getElanInterfaces();
478 if (elanInterfaces == null || elanInterfaces.isEmpty()) {
481 for (String elanInterface : elanInterfaces) {
482 ElanInterfaceMac elanInterfaceMac = ElanUtils.getElanInterfaceMacByInterfaceName(elanInterface);
483 if (elanInterfaceMac.getMacEntry() != null && elanInterfaceMac.getMacEntry().size() > 0) {
484 List<MacEntry> macEntries = elanInterfaceMac.getMacEntry();
485 for (MacEntry macEntry : macEntries) {
487 deleteStaticMacAddress(elanInstanceName, elanInterface, macEntry.getMacAddress().getValue());
488 } catch (MacNotFoundException e) {
489 logger.error("Mac Not Found Exception {}", e);
499 public void close() throws Exception {
500 this.elanInstanceManager.close();
501 this.elanL2GatewayProvider.close();
504 public static List<PhysAddress> getPhysAddress(List<String> macAddress) {
505 List<PhysAddress> physAddresses = new ArrayList<>();
506 for (String mac : macAddress) {
507 physAddresses.add(new PhysAddress(mac));
509 return physAddresses;
512 public List<PhysAddress> getUpdatedPhyAddress(List<PhysAddress> originalAddresses,
513 List<PhysAddress> updatePhyAddresses) {
514 if (updatePhyAddresses != null && !updatePhyAddresses.isEmpty()) {
515 List<PhysAddress> existingClonedPhyAddress = new ArrayList<>();
516 if (originalAddresses != null && !originalAddresses.isEmpty()) {
517 existingClonedPhyAddress.addAll(0, originalAddresses);
518 originalAddresses.removeAll(updatePhyAddresses);
519 updatePhyAddresses.removeAll(existingClonedPhyAddress);
522 return updatePhyAddresses;
526 public ElanInstance getElanInstance(String elanName) {
527 return ElanUtils.getElanInstanceByName(elanName);
531 public List<ElanInstance> getElanInstances() {
532 List<ElanInstance> elanList = new ArrayList<>();
533 InstanceIdentifier<ElanInstances> elanInstancesIdentifier = InstanceIdentifier.builder(ElanInstances.class)
535 Optional<ElanInstances> elansOptional = ElanUtils.read(broker, LogicalDatastoreType.CONFIGURATION,
536 elanInstancesIdentifier);
537 if (elansOptional.isPresent()) {
538 elanList.addAll(elansOptional.get().getElanInstance());
544 public List<String> getElanInterfaces(String elanInstanceName) {
545 List<String> elanInterfaces = new ArrayList<>();
546 InstanceIdentifier<ElanInterfaces> elanInterfacesIdentifier = InstanceIdentifier.builder(ElanInterfaces.class)
548 Optional<ElanInterfaces> elanInterfacesOptional = ElanUtils.read(broker, LogicalDatastoreType.CONFIGURATION,
549 elanInterfacesIdentifier);
550 if (!elanInterfacesOptional.isPresent()) {
551 return elanInterfaces;
553 List<ElanInterface> elanInterfaceList = elanInterfacesOptional.get().getElanInterface();
554 for (ElanInterface elanInterface : elanInterfaceList) {
555 if (elanInterface.getElanInstanceName().equals(elanInstanceName)) {
556 elanInterfaces.add(elanInterface.getName());
559 return elanInterfaces;
562 public boolean getGenerateIntBridgeMac() {
563 return generateIntBridgeMac;
566 public void setGenerateIntBridgeMac(boolean generateIntBridgeMac) {
567 this.generateIntBridgeMac = generateIntBridgeMac;
571 public void createExternalElanNetworks(Node node) {
572 if (!bridgeMgr.isIntegrationBridge(node)) {
576 List<ElanInstance> elanInstances = getElanInstances();
577 if (elanInstances == null || elanInstances.isEmpty()) {
578 logger.trace("No ELAN instances found");
582 for (ElanInstance elanInstance : elanInstances) {
583 String interfaceName = getExtInterfaceName(node, elanInstance.getPhysicalNetworkName());
584 createExternalElanNetwork(elanInstance, node, interfaceName);
589 public void createExternalElanNetwork(ElanInstance elanInstance) {
590 if (elanInstance.getPhysicalNetworkName() == null) {
591 logger.trace("No physical network attached to {}", elanInstance.getElanInstanceName());
595 List<Node> nodes = bridgeMgr.southboundUtils.getOvsdbNodes();
596 if (nodes == null || nodes.isEmpty()) {
597 logger.trace("No OVS nodes found while creating external network for ELAN {}",
598 elanInstance.getElanInstanceName());
602 for (Node node : nodes) {
603 if (bridgeMgr.isIntegrationBridge(node)) {
604 String interfaceName = getExtInterfaceName(node, elanInstance.getPhysicalNetworkName());
605 createExternalElanNetwork(elanInstance, node, interfaceName);
610 private void createExternalElanNetwork(ElanInstance elanInstance, Node node, String interfaceName) {
611 if (interfaceName == null) {
612 logger.trace("No physial interface is attached to {} node {}", elanInstance.getPhysicalNetworkName(),
613 node.getNodeId().getValue());
616 String elanInterfaceName = createIetfInterfaces(elanInstance, interfaceName);
617 addElanInterface(elanInstance.getElanInstanceName(), elanInterfaceName, null, null);
621 * Create ietf-interfaces based on the ELAN segment type.<br>
622 * For segment type flat - create transparent interface pointing to the
623 * patch-port attached to the physnet port.<br>
624 * For segment type vlan - create trunk interface pointing to the patch-port
625 * attached to the physnet port + trunk-member interface pointing to the
628 * @param elanInstance
631 * parent interface name
632 * @return the name of the interface to be added to the ELAN instance i.e.
633 * trunk-member name for vlan network and transparent for flat
634 * network or null otherwise
636 private String createIetfInterfaces(ElanInstance elanInstance, String parentRef) {
637 String interfaceName = null;
640 if (ElanUtils.isFlat(elanInstance)) {
641 interfaceName = parentRef + IfmConstants.OF_URI_PREFIX + "flat";
642 interfaceManager.createVLANInterface(interfaceName, parentRef, null, null, null,
643 IfL2vlan.L2vlanMode.Transparent);
644 } else if (ElanUtils.isVlan(elanInstance)) {
645 String trunkName = parentRef + IfmConstants.OF_URI_PREFIX + "trunk";
646 interfaceManager.createVLANInterface(interfaceName, parentRef, null, null, null,
647 IfL2vlan.L2vlanMode.Trunk);
648 Long segmentationId = elanInstance.getSegmentationId();
649 interfaceName = parentRef + IfmConstants.OF_URI_PREFIX + segmentationId;
650 interfaceManager.createVLANInterface(interfaceName, trunkName, null, segmentationId.intValue(), null,
651 IfL2vlan.L2vlanMode.TrunkMember);
653 } catch (InterfaceAlreadyExistsException e) {
654 logger.trace("Interface {} was already created", interfaceName);
657 return interfaceName;
660 private String getExtInterfaceName(Node node, String physicalNetworkName) {
661 if (physicalNetworkName == null) {
665 String providerMappingValue = bridgeMgr.getProviderMappingValue(node, physicalNetworkName);
666 if (providerMappingValue == null) {
667 logger.trace("No provider mapping found for physicalNetworkName {} node {}", physicalNetworkName,
668 node.getNodeId().getValue());
672 return bridgeMgr.southboundUtils.getDataPathId(node) + IfmConstants.OF_URI_SEPARATOR
673 + bridgeMgr.getIntBridgePortNameFor(node, providerMappingValue);