Search in sources :

Example 1 with ElanInterfaceMac

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan._interface.forwarding.entries.ElanInterfaceMac in project netvirt by opendaylight.

the class ElanPacketInHandler method onPacketReceived.

@Override
public void onPacketReceived(PacketReceived notification) {
    Class<? extends PacketInReason> pktInReason = notification.getPacketInReason();
    short tableId = notification.getTableId().getValue();
    if (pktInReason == NoMatch.class && tableId == NwConstants.ELAN_SMAC_TABLE) {
        ElanManagerCounters.unknown_smac_pktin_rcv.inc();
        try {
            byte[] data = notification.getPayload();
            Ethernet res = new Ethernet();
            res.deserialize(data, 0, data.length * NetUtils.NUM_BITS_IN_A_BYTE);
            byte[] srcMac = res.getSourceMACAddress();
            final String macAddress = NWUtil.toStringMacAddress(srcMac);
            final BigInteger metadata = notification.getMatch().getMetadata().getMetadata();
            final long elanTag = MetaDataUtil.getElanTagFromMetadata(metadata);
            long portTag = MetaDataUtil.getLportFromMetadata(metadata).intValue();
            Optional<IfIndexInterface> interfaceInfoOp = elanUtils.getInterfaceInfoByInterfaceTag(portTag);
            if (!interfaceInfoOp.isPresent()) {
                LOG.warn("There is no interface for given portTag {}", portTag);
                return;
            }
            String interfaceName = interfaceInfoOp.get().getInterfaceName();
            LOG.debug("Received a packet with srcMac: {} ElanTag: {} PortTag: {} InterfaceName: {}", macAddress, elanTag, portTag, interfaceName);
            ElanTagName elanTagName = elanUtils.getElanInfoByElanTag(elanTag);
            if (elanTagName == null) {
                LOG.warn("not able to find elanTagName in elan-tag-name-map for elan tag {}", elanTag);
                return;
            }
            ElanInterfaceMac elanInterfaceMac = elanUtils.getElanInterfaceMacByInterfaceName(interfaceName);
            if (elanInterfaceMac == null) {
                LOG.info("There is no ElanInterfaceForwardingEntryDS created for interface :{}", interfaceName);
                return;
            }
            String elanName = elanTagName.getName();
            PhysAddress physAddress = new PhysAddress(macAddress);
            MacEntry oldMacEntry = elanUtils.getMacEntryForElanInstance(elanName, physAddress).orNull();
            boolean isVlanOrFlatProviderIface = interfaceManager.isExternalInterface(interfaceName);
            Optional<IpAddress> srcIpAddress = elanUtils.getSourceIpAddress(res);
            MacEntry newMacEntry = null;
            BigInteger timeStamp = new BigInteger(String.valueOf(System.currentTimeMillis()));
            if (!srcIpAddress.isPresent()) {
                newMacEntry = new MacEntryBuilder().setInterface(interfaceName).setMacAddress(physAddress).setKey(new MacEntryKey(physAddress)).setControllerLearnedForwardingEntryTimestamp(timeStamp).setIsStaticAddress(false).build();
            } else {
                newMacEntry = new MacEntryBuilder().setInterface(interfaceName).setMacAddress(physAddress).setIpPrefix(srcIpAddress.get()).setKey(new MacEntryKey(physAddress)).setControllerLearnedForwardingEntryTimestamp(timeStamp).setIsStaticAddress(false).build();
            }
            if (srcIpAddress.isPresent()) {
                String prefix = srcIpAddress.get().getIpv4Address().getValue();
                InterfaceInfo interfaceInfo = interfaceManager.getInterfaceInfo(interfaceName);
                ElanInstance elanInstance = elanInstanceCache.get(elanName).orNull();
                evpnUtils.advertisePrefix(elanInstance, macAddress, prefix, interfaceName, interfaceInfo.getDpId());
            }
            enqueueJobForMacSpecificTasks(macAddress, elanTag, interfaceName, elanName, physAddress, oldMacEntry, newMacEntry, isVlanOrFlatProviderIface);
            ElanInstance elanInstance = elanInstanceCache.get(elanName).orNull();
            InterfaceInfo interfaceInfo = interfaceManager.getInterfaceInfo(interfaceName);
            if (interfaceInfo == null) {
                LOG.trace("Interface:{} is not present under Config DS", interfaceName);
                return;
            }
            enqueueJobForDPNSpecificTasks(macAddress, elanTag, interfaceName, physAddress, elanInstance, interfaceInfo, oldMacEntry, newMacEntry, isVlanOrFlatProviderIface);
        } catch (PacketException e) {
            LOG.error("Failed to decode packet: {}", notification, e);
        }
    }
}
Also used : ElanTagName(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.tag.name.map.ElanTagName) ElanInstance(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance) MacEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.forwarding.entries.MacEntry) IfIndexInterface(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406._if.indexes._interface.map.IfIndexInterface) PacketException(org.opendaylight.openflowplugin.libraries.liblldp.PacketException) Ethernet(org.opendaylight.genius.mdsalutil.packet.Ethernet) BigInteger(java.math.BigInteger) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) InterfaceInfo(org.opendaylight.genius.interfacemanager.globals.InterfaceInfo) MacEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.forwarding.entries.MacEntryBuilder) NoMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.NoMatch) ElanInterfaceMac(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan._interface.forwarding.entries.ElanInterfaceMac) PhysAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress) MacEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.forwarding.entries.MacEntryKey)

Example 2 with ElanInterfaceMac

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan._interface.forwarding.entries.ElanInterfaceMac in project netvirt by opendaylight.

the class ElanInterfaceManager method createElanInterfaceTablesList.

private void createElanInterfaceTablesList(String interfaceName, WriteTransaction tx) {
    InstanceIdentifier<ElanInterfaceMac> elanInterfaceMacTables = ElanUtils.getElanInterfaceMacEntriesOperationalDataPath(interfaceName);
    Optional<ElanInterfaceMac> interfaceMacTables = ElanUtils.read(broker, LogicalDatastoreType.OPERATIONAL, elanInterfaceMacTables);
    // Static-Mac Entries..
    if (!interfaceMacTables.isPresent()) {
        ElanInterfaceMac elanInterfaceMacTable = new ElanInterfaceMacBuilder().setElanInterface(interfaceName).setKey(new ElanInterfaceMacKey(interfaceName)).build();
        tx.put(LogicalDatastoreType.OPERATIONAL, ElanUtils.getElanInterfaceMacEntriesOperationalDataPath(interfaceName), elanInterfaceMacTable, WriteTransaction.CREATE_MISSING_PARENTS);
    }
}
Also used : ElanInterfaceMacKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan._interface.forwarding.entries.ElanInterfaceMacKey) ElanInterfaceMac(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan._interface.forwarding.entries.ElanInterfaceMac) ElanInterfaceMacBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan._interface.forwarding.entries.ElanInterfaceMacBuilder)

Example 3 with ElanInterfaceMac

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan._interface.forwarding.entries.ElanInterfaceMac in project netvirt by opendaylight.

the class ElanServiceProvider method flushMACTable.

@Override
public void flushMACTable(String elanInstanceName) {
    Elan elanInfo = ElanUtils.getElanByName(broker, elanInstanceName);
    if (elanInfo == null) {
        return;
    }
    List<String> elanInterfaces = elanInfo.getElanInterfaces();
    if (elanInterfaces == null || elanInterfaces.isEmpty()) {
        return;
    }
    for (String elanInterface : elanInterfaces) {
        ElanInterfaceMac elanInterfaceMac = elanUtils.getElanInterfaceMacByInterfaceName(elanInterface);
        if (elanInterfaceMac.getMacEntry() != null && elanInterfaceMac.getMacEntry().size() > 0) {
            List<MacEntry> macEntries = elanInterfaceMac.getMacEntry();
            for (MacEntry macEntry : macEntries) {
                deleteStaticMacAddress(elanInterface, macEntry.getMacAddress().getValue());
            }
        }
    }
}
Also used : Elan(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.state.Elan) MacEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.forwarding.entries.MacEntry) ElanInterfaceMac(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan._interface.forwarding.entries.ElanInterfaceMac)

Example 4 with ElanInterfaceMac

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan._interface.forwarding.entries.ElanInterfaceMac in project netvirt by opendaylight.

the class ElanUtils method getElanInterfaceMacAddresses.

/**
 * Gets the elan interface mac addresses.
 *
 * @param interfaceName
 *            the interface name
 * @return the elan interface mac addresses
 */
public List<PhysAddress> getElanInterfaceMacAddresses(String interfaceName) {
    List<PhysAddress> macAddresses = new ArrayList<>();
    ElanInterfaceMac elanInterfaceMac = getElanInterfaceMacByInterfaceName(interfaceName);
    if (elanInterfaceMac != null && elanInterfaceMac.getMacEntry() != null) {
        List<MacEntry> macEntries = elanInterfaceMac.getMacEntry();
        for (MacEntry macEntry : macEntries) {
            macAddresses.add(macEntry.getMacAddress());
        }
    }
    return macAddresses;
}
Also used : MacEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.forwarding.entries.MacEntry) ArrayList(java.util.ArrayList) PhysAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress) ElanInterfaceMac(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan._interface.forwarding.entries.ElanInterfaceMac)

Example 5 with ElanInterfaceMac

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan._interface.forwarding.entries.ElanInterfaceMac in project netvirt by opendaylight.

the class ElanServiceProvider method getElanMacTable.

@Override
public Collection<MacEntry> getElanMacTable(String elanInstanceName) {
    Elan elanInfo = ElanUtils.getElanByName(broker, elanInstanceName);
    List<MacEntry> macAddress = new ArrayList<>();
    if (elanInfo == null) {
        return macAddress;
    }
    List<String> elanInterfaces = elanInfo.getElanInterfaces();
    if (elanInterfaces != null && elanInterfaces.size() > 0) {
        for (String elanInterface : elanInterfaces) {
            ElanInterfaceMac elanInterfaceMac = elanUtils.getElanInterfaceMacByInterfaceName(elanInterface);
            if (elanInterfaceMac != null && elanInterfaceMac.getMacEntry() != null && elanInterfaceMac.getMacEntry().size() > 0) {
                macAddress.addAll(elanInterfaceMac.getMacEntry());
            }
        }
    }
    return macAddress;
}
Also used : Elan(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.state.Elan) MacEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.forwarding.entries.MacEntry) ArrayList(java.util.ArrayList) ElanInterfaceMac(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan._interface.forwarding.entries.ElanInterfaceMac)

Aggregations

ElanInterfaceMac (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan._interface.forwarding.entries.ElanInterfaceMac)9 MacEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.forwarding.entries.MacEntry)8 BigInteger (java.math.BigInteger)4 ArrayList (java.util.ArrayList)3 InterfaceInfo (org.opendaylight.genius.interfacemanager.globals.InterfaceInfo)3 PhysAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress)3 ElanDpnInterfaces (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanDpnInterfaces)3 DpnInterfaces (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.dpn.interfaces.elan.dpn.interfaces.list.DpnInterfaces)3 Elan (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.state.Elan)3 ReadWriteTransaction (org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction)2 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)2 ElanDpnInterfacesList (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.dpn.interfaces.ElanDpnInterfacesList)2 Optional (com.google.common.base.Optional)1 Preconditions (com.google.common.base.Preconditions)1 Lists (com.google.common.collect.Lists)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1