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.elan.rev150602.elan.tag.name.map.ElanTagName;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.elan.rev150602.forwarding.entries.MacEntry;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._if.indexes._interface.map.IfIndexInterface;
24 //import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331._if.indexes._interface.map.IfIndexInterface;
25 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
29 import java.math.BigInteger;
31 public class ElanSmacFlowEventListener implements SalFlowListener {
32 private final DataBroker broker;
33 private IMdsalApiManager mdsalManager;
34 private IInterfaceManager interfaceManager;
35 private IITMProvider itmManager;
36 private static final Logger logger = LoggerFactory.getLogger(ElanSmacFlowEventListener.class);
38 public ElanSmacFlowEventListener(DataBroker dataBroker) {
41 private SalFlowService salFlowService;
43 public SalFlowService getSalFlowService() {
44 return this.salFlowService;
47 public void setSalFlowService(final SalFlowService salFlowService) {
48 this.salFlowService = salFlowService;
50 public void setInterfaceManager(IInterfaceManager interfaceManager) {
51 this.interfaceManager = interfaceManager;
55 public void setIITMManager(IITMProvider itmManager) {
56 this.itmManager = itmManager;
58 public void setMdSalApiManager(IMdsalApiManager mdsalManager) {
59 this.mdsalManager = mdsalManager;
62 public void onFlowAdded(FlowAdded arg0) {
63 // TODO Auto-generated method stub
68 public void onFlowRemoved(FlowRemoved arg0) {
69 // TODO Auto-generated method stub
74 public void onFlowUpdated(FlowUpdated arg0) {
75 // TODO Auto-generated method stub
80 public void onNodeErrorNotification(NodeErrorNotification arg0) {
81 // TODO Auto-generated method stub
86 public void onNodeExperimenterErrorNotification(NodeExperimenterErrorNotification arg0) {
87 // TODO Auto-generated method stub
92 public void onSwitchFlowRemoved(SwitchFlowRemoved switchFlowRemoved) {
93 short tableId = switchFlowRemoved.getTableId();
94 if (tableId == ElanConstants.ELAN_SMAC_TABLE) {
95 BigInteger metadata = switchFlowRemoved.getMatch().getMetadata().getMetadata();
96 long elanTag = MetaDataUtil.getElanTagFromMetadata(metadata);
97 ElanTagName elanTagInfo = ElanUtils.getElanInfoByElanTag(elanTag);
98 if (elanTagInfo == null) {
101 String srcMacAddress = switchFlowRemoved.getMatch().getEthernetMatch()
102 .getEthernetSource().getAddress().getValue().toUpperCase();
103 int portTag = MetaDataUtil.getLportFromMetadata(metadata).intValue();
105 logger.debug(String.format("Flow removed event on SMAC flow entry. But having port Tag as 0 "));
108 IfIndexInterface existingInterfaceInfo = ElanUtils.getInterfaceInfoByInterfaceTag(portTag);
109 String interfaceName = existingInterfaceInfo.getInterfaceName();
110 PhysAddress physAddress = new PhysAddress(srcMacAddress);
111 if (interfaceName == null) {
112 logger.error(String.format("LPort record not found for tag %d", portTag));
115 MacEntry macEntry = ElanUtils.getInterfaceMacEntriesOperationalDataPath(interfaceName, physAddress);
116 InterfaceInfo interfaceInfo = interfaceManager.getInterfaceInfo(interfaceName);
117 if(macEntry != null && interfaceInfo != null) {
118 ElanUtils.deleteMacFlows(ElanUtils.getElanInstanceByName(elanTagInfo.getName()), interfaceInfo, macEntry);
120 InstanceIdentifier<MacEntry> macEntryId = ElanUtils.getInterfaceMacEntriesIdentifierOperationalDataPath(interfaceName, physAddress);
121 ElanUtils.delete(broker, LogicalDatastoreType.OPERATIONAL, macEntryId);