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
8 package org.opendaylight.vpnservice.elan.internal;
10 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
11 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
12 import org.opendaylight.vpnservice.elan.utils.ElanConstants;
13 import org.opendaylight.vpnservice.elan.utils.ElanUtils;
14 import org.opendaylight.vpnservice.interfacemgr.globals.InterfaceInfo;
15 import org.opendaylight.vpnservice.interfacemgr.interfaces.IInterfaceManager;
16 import org.opendaylight.vpnservice.itm.api.IITMProvider;
17 import org.opendaylight.vpnservice.mdsalutil.MetaDataUtil;
18 import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager;
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.flow.service.rev130819.*;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.alivenessmonitor.rev150629.LivenessState;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.elan.rev150602.elan.tag.name.map.ElanTagName;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.elan.rev150602.forwarding.entries.MacEntry;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._if.indexes._interface.map.IfIndexInterface;
25 //import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331._if.indexes._interface.map.IfIndexInterface;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29 import com.google.common.util.concurrent.Futures;
30 import com.google.common.util.concurrent.ListenableFuture;
31 import com.google.common.util.concurrent.FutureCallback;
32 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
35 import java.math.BigInteger;
37 public class ElanSmacFlowEventListener implements SalFlowListener {
38 private final DataBroker broker;
39 private IMdsalApiManager mdsalManager;
40 private IInterfaceManager interfaceManager;
41 private static final Logger logger = LoggerFactory.getLogger(ElanSmacFlowEventListener.class);
43 public ElanSmacFlowEventListener(DataBroker dataBroker) {
46 private SalFlowService salFlowService;
48 public SalFlowService getSalFlowService() {
49 return this.salFlowService;
52 public void setSalFlowService(final SalFlowService salFlowService) {
53 this.salFlowService = salFlowService;
55 public void setInterfaceManager(IInterfaceManager interfaceManager) {
56 this.interfaceManager = interfaceManager;
60 public void setMdSalApiManager(IMdsalApiManager mdsalManager) {
61 this.mdsalManager = mdsalManager;
64 public void onFlowAdded(FlowAdded arg0) {
65 // TODO Auto-generated method stub
70 public void onFlowRemoved(FlowRemoved arg0) {
71 // TODO Auto-generated method stub
76 public void onFlowUpdated(FlowUpdated arg0) {
77 // TODO Auto-generated method stub
82 public void onNodeErrorNotification(NodeErrorNotification arg0) {
83 // TODO Auto-generated method stub
88 public void onNodeExperimenterErrorNotification(NodeExperimenterErrorNotification arg0) {
89 // TODO Auto-generated method stub
94 public void onSwitchFlowRemoved(SwitchFlowRemoved switchFlowRemoved) {
95 short tableId = switchFlowRemoved.getTableId();
96 if (tableId == ElanConstants.ELAN_SMAC_TABLE) {
97 BigInteger metadata = switchFlowRemoved.getMatch().getMetadata().getMetadata();
98 long elanTag = MetaDataUtil.getElanTagFromMetadata(metadata);
99 ElanTagName elanTagInfo = ElanUtils.getElanInfoByElanTag(elanTag);
100 if (elanTagInfo == null) {
103 String srcMacAddress = switchFlowRemoved.getMatch().getEthernetMatch()
104 .getEthernetSource().getAddress().getValue().toUpperCase();
105 int portTag = MetaDataUtil.getLportFromMetadata(metadata).intValue();
107 logger.debug(String.format("Flow removed event on SMAC flow entry. But having port Tag as 0 "));
110 IfIndexInterface existingInterfaceInfo = ElanUtils.getInterfaceInfoByInterfaceTag(portTag);
111 String interfaceName = existingInterfaceInfo.getInterfaceName();
112 PhysAddress physAddress = new PhysAddress(srcMacAddress);
113 if (interfaceName == null) {
114 logger.error(String.format("LPort record not found for tag %d", portTag));
117 MacEntry macEntry = ElanUtils.getInterfaceMacEntriesOperationalDataPath(interfaceName, physAddress);
118 InterfaceInfo interfaceInfo = interfaceManager.getInterfaceInfo(interfaceName);
119 if(macEntry != null && interfaceInfo != null) {
120 ElanUtils.deleteMacFlows(ElanUtils.getElanInstanceByName(elanTagInfo.getName()), interfaceInfo, macEntry);
122 InstanceIdentifier<MacEntry> macEntryIdForElanInterface = ElanUtils.getInterfaceMacEntriesIdentifierOperationalDataPath(interfaceName, physAddress);
123 InstanceIdentifier<MacEntry> macEntryIdForElanInstance = ElanUtils.getMacEntryOperationalDataPath(elanTagInfo.getName(), physAddress);
124 WriteTransaction tx = broker.newWriteOnlyTransaction();
125 tx.delete(LogicalDatastoreType.OPERATIONAL, macEntryIdForElanInterface);
126 tx.delete(LogicalDatastoreType.OPERATIONAL, macEntryIdForElanInstance);
127 ListenableFuture<Void> writeResult = tx.submit();
130 Futures.addCallback(writeResult, new FutureCallback<Void>() {
132 public void onSuccess(Void noarg) {
133 logger.debug("Successfully removed macEntries from Operational Datastore");
137 public void onFailure(Throwable error) {
138 logger.debug("Error while removing macEntries from Operational Datastore", error);