Search in sources :

Example 11 with InterfaceInfo

use of org.opendaylight.genius.interfacemanager.globals.InterfaceInfo in project netvirt by opendaylight.

the class AclServiceTestBase method newInterfaceInfo.

private InterfaceInfo newInterfaceInfo(String testInterfaceName) {
    InterfaceInfo interfaceInfo = new InterfaceInfo(BigInteger.valueOf(789), "port1");
    interfaceInfo.setInterfaceName(testInterfaceName);
    return interfaceInfo;
}
Also used : InterfaceInfo(org.opendaylight.genius.interfacemanager.globals.InterfaceInfo)

Example 12 with InterfaceInfo

use of org.opendaylight.genius.interfacemanager.globals.InterfaceInfo in project netvirt by opendaylight.

the class NaptEventHandler method prepareAndSendPacketOut.

private void prepareAndSendPacketOut(NAPTEntryEvent naptEntryEvent, Long routerId) {
    // Send Packetout - tcp or udp packets which got punted to controller.
    BigInteger metadata = naptEntryEvent.getPacketReceived().getMatch().getMetadata().getMetadata();
    byte[] inPayload = naptEntryEvent.getPacketReceived().getPayload();
    Ethernet ethPkt = new Ethernet();
    if (inPayload != null) {
        try {
            ethPkt.deserialize(inPayload, 0, inPayload.length * NetUtils.NUM_BITS_IN_A_BYTE);
        } catch (PacketException e) {
            LOG.error("prepareAndSendPacketOut : Failed to decode Packet", e);
            return;
        }
    }
    long portTag = MetaDataUtil.getLportFromMetadata(metadata).intValue();
    LOG.debug("prepareAndSendPacketOut : portTag from incoming packet is {}", portTag);
    String interfaceName = getInterfaceNameFromTag(portTag);
    LOG.debug("prepareAndSendPacketOut : interfaceName fetched from portTag is {}", interfaceName);
    org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface iface = null;
    int vlanId = 0;
    iface = interfaceManager.getInterfaceInfoFromConfigDataStore(interfaceName);
    if (iface == null) {
        LOG.error("prepareAndSendPacketOut : Unable to read interface {} from config DataStore", interfaceName);
        return;
    }
    List<ActionInfo> actionInfos = new ArrayList<>();
    IfL2vlan ifL2vlan = iface.getAugmentation(IfL2vlan.class);
    if (ifL2vlan != null && ifL2vlan.getVlanId() != null) {
        vlanId = ifL2vlan.getVlanId().getValue() == null ? 0 : ifL2vlan.getVlanId().getValue();
    }
    InterfaceInfo infInfo = interfaceManager.getInterfaceInfoFromOperationalDataStore(interfaceName);
    if (infInfo == null) {
        LOG.error("prepareAndSendPacketOut : error in getting interfaceInfo from Operation DS");
        return;
    }
    byte[] pktOut = buildNaptPacketOut(ethPkt);
    if (ethPkt.getEtherType() != (short) NwConstants.ETHTYPE_802_1Q) {
        // VLAN Access port
        LOG.debug("prepareAndSendPacketOut : vlanId is {}", vlanId);
        if (vlanId != 0) {
            // Push vlan
            actionInfos.add(new ActionPushVlan(0));
            actionInfos.add(new ActionSetFieldVlanVid(1, vlanId));
        } else {
            LOG.debug("prepareAndSendPacketOut : No vlanId {}, may be untagged", vlanId);
        }
    } else {
        // VLAN Trunk Port
        LOG.debug("prepareAndSendPacketOut : This is VLAN Trunk port case - need not do VLAN tagging again");
    }
    if (pktOut != null) {
        String routerName = NatUtil.getRouterName(dataBroker, routerId);
        long tunId = NatUtil.getTunnelIdForNonNaptToNaptFlow(dataBroker, elanManager, idManager, routerId, routerName);
        sendNaptPacketOut(pktOut, infInfo, actionInfos, tunId);
    } else {
        LOG.warn("prepareAndSendPacketOut : Unable to send Packet Out");
    }
}
Also used : ArrayList(java.util.ArrayList) ActionSetFieldVlanVid(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldVlanVid) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) ActionPushVlan(org.opendaylight.genius.mdsalutil.actions.ActionPushVlan) PacketException(org.opendaylight.openflowplugin.libraries.liblldp.PacketException) Ethernet(org.opendaylight.genius.mdsalutil.packet.Ethernet) BigInteger(java.math.BigInteger) InterfaceInfo(org.opendaylight.genius.interfacemanager.globals.InterfaceInfo) IfL2vlan(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfL2vlan)

Example 13 with InterfaceInfo

use of org.opendaylight.genius.interfacemanager.globals.InterfaceInfo in project netvirt by opendaylight.

the class ElanServiceTest method checkSMAC.

@Test
public void checkSMAC() throws Exception {
    // Create Elan instance
    createElanInstance(ExpectedObjects.ELAN1, ExpectedObjects.ELAN1_SEGMENT_ID);
    awaitForElanTag(ExpectedObjects.ELAN1);
    // Add Elan interface
    InterfaceInfo interfaceInfo = ELAN_INTERFACES.get(ELAN1 + ":" + DPN1MAC1).getLeft();
    addElanInterface(ExpectedObjects.ELAN1, interfaceInfo, DPN1IP1);
    // Read Elan instance
    InstanceIdentifier<ElanInstance> elanInstanceIid = InstanceIdentifier.builder(ElanInstances.class).child(ElanInstance.class, new ElanInstanceKey(ExpectedObjects.ELAN1)).build();
    ElanInstance actualElanInstances = singleTxdataBroker.syncRead(CONFIGURATION, elanInstanceIid);
    // Read and Compare SMAC flow
    String flowId = new StringBuffer().append(NwConstants.ELAN_SMAC_TABLE).append(actualElanInstances.getElanTag()).append(DPN1_ID).append(interfaceInfo.getInterfaceTag()).append(interfaceInfo.getMacAddress()).toString();
    InstanceIdentifier<Flow> flowInstanceIidSrc = getFlowIid(NwConstants.ELAN_SMAC_TABLE, new FlowId(flowId), DPN1_ID);
    awaitForData(LogicalDatastoreType.CONFIGURATION, flowInstanceIidSrc);
    Flow flowSrc = singleTxdataBroker.syncRead(CONFIGURATION, flowInstanceIidSrc);
    flowSrc = getFlowWithoutCookie(flowSrc);
    Flow expected = ExpectedObjects.checkSmac(flowId, interfaceInfo, actualElanInstances);
    AssertDataObjects.assertEqualBeans(expected, flowSrc);
}
Also used : ElanInstance(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance) FlowId(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId) ElanInstanceKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstanceKey) InterfaceInfo(org.opendaylight.genius.interfacemanager.globals.InterfaceInfo) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow) Test(org.junit.Test)

Example 14 with InterfaceInfo

use of org.opendaylight.genius.interfacemanager.globals.InterfaceInfo in project netvirt by opendaylight.

the class DhcpPktHandler method onPacketReceived.

// TODO: Handle this in a separate thread
@Override
public void onPacketReceived(PacketReceived packet) {
    if (!config.isControllerDhcpEnabled()) {
        return;
    }
    Class<? extends PacketInReason> pktInReason = packet.getPacketInReason();
    short tableId = packet.getTableId().getValue();
    if ((tableId == NwConstants.DHCP_TABLE || tableId == NwConstants.DHCP_TABLE_EXTERNAL_TUNNEL) && isPktInReasonSendtoCtrl(pktInReason)) {
        byte[] inPayload = packet.getPayload();
        Ethernet ethPkt = new Ethernet();
        try {
            ethPkt.deserialize(inPayload, 0, inPayload.length * NetUtils.NUM_BITS_IN_A_BYTE);
        } catch (PacketException e) {
            LOG.warn("Failed to decode DHCP Packet.", e);
            LOG.trace("Received packet {}", packet);
            return;
        }
        DHCP pktIn;
        pktIn = getDhcpPktIn(ethPkt);
        if (pktIn != null) {
            LOG.trace("DHCPPkt received: {}", pktIn);
            LOG.trace("Received Packet: {}", packet);
            BigInteger metadata = packet.getMatch().getMetadata().getMetadata();
            long portTag = MetaDataUtil.getLportFromMetadata(metadata).intValue();
            String macAddress = DHCPUtils.byteArrayToString(ethPkt.getSourceMACAddress());
            BigInteger tunnelId = packet.getMatch().getTunnel() == null ? null : packet.getMatch().getTunnel().getTunnelId();
            String interfaceName = getInterfaceNameFromTag(portTag);
            InterfaceInfo interfaceInfo = interfaceManager.getInterfaceInfoFromOperationalDataStore(interfaceName);
            if (interfaceInfo == null) {
                LOG.error("Failed to get interface info for interface name {}", interfaceName);
                return;
            }
            Port port;
            if (tunnelId != null) {
                port = dhcpExternalTunnelManager.readVniMacToPortCache(tunnelId, macAddress);
            } else {
                port = getNeutronPort(interfaceName);
            }
            Subnet subnet = getNeutronSubnet(port);
            String serverMacAddress = interfaceInfo.getMacAddress();
            String serverIp = null;
            if (subnet != null) {
                java.util.Optional<SubnetToDhcpPort> dhcpPortData = DhcpServiceUtils.getSubnetDhcpPortData(broker, subnet.getUuid().getValue());
                /* If enable_dhcp_service flag was enabled and an ODL network DHCP Port data was made available use
                     * the ports Fixed IP as server IP for DHCP communication.
                     */
                if (dhcpPortData.isPresent()) {
                    serverIp = dhcpPortData.get().getPortFixedip();
                    serverMacAddress = dhcpPortData.get().getPortMacaddress();
                } else {
                    // DHCP Neutron Port not found for this network
                    LOG.error("Neutron DHCP port is not available for the Subnet {} and port {}.", subnet.getUuid(), port.getUuid());
                    return;
                }
            }
            DHCP replyPkt = handleDhcpPacket(pktIn, interfaceName, macAddress, port, subnet, serverIp);
            if (replyPkt == null) {
                LOG.warn("Unable to construct reply packet for interface name {}", interfaceName);
                return;
            }
            byte[] pktOut = getDhcpPacketOut(replyPkt, ethPkt, serverMacAddress);
            sendPacketOut(pktOut, interfaceInfo.getDpId(), interfaceName, tunnelId);
        }
    }
}
Also used : SubnetToDhcpPort(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dhcpservice.api.rev150710.subnet.dhcp.port.data.SubnetToDhcpPort) Port(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port) PacketException(org.opendaylight.openflowplugin.libraries.liblldp.PacketException) DHCP(org.opendaylight.netvirt.dhcpservice.api.DHCP) SubnetToDhcpPort(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dhcpservice.api.rev150710.subnet.dhcp.port.data.SubnetToDhcpPort) Ethernet(org.opendaylight.genius.mdsalutil.packet.Ethernet) BigInteger(java.math.BigInteger) InterfaceInfo(org.opendaylight.genius.interfacemanager.globals.InterfaceInfo) Subnet(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet)

Example 15 with InterfaceInfo

use of org.opendaylight.genius.interfacemanager.globals.InterfaceInfo in project netvirt by opendaylight.

the class PolicyServiceFlowUtil method getIngressInterfaceMatches.

public List<MatchInfoBase> getIngressInterfaceMatches(String ingressInterface) {
    InterfaceInfo interfaceInfo = interfaceManager.getInterfaceInfo(ingressInterface);
    if (interfaceInfo == null) {
        LOG.warn("No interface info found for {}", ingressInterface);
        return Collections.emptyList();
    }
    int lportTag = interfaceInfo.getInterfaceTag();
    return Collections.singletonList(new MatchMetadata(MetaDataUtil.getMetadataLPort(lportTag), MetaDataUtil.METADATA_MASK_LPORT_TAG));
}
Also used : MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) InterfaceInfo(org.opendaylight.genius.interfacemanager.globals.InterfaceInfo)

Aggregations

InterfaceInfo (org.opendaylight.genius.interfacemanager.globals.InterfaceInfo)40 BigInteger (java.math.BigInteger)16 ElanInstance (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance)12 PhysAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress)8 MacEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.forwarding.entries.MacEntry)8 ArrayList (java.util.ArrayList)7 Collections (java.util.Collections)7 Interface (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface)6 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)5 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)5 Bucket (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket)5 ElanInterfaceMac (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan._interface.forwarding.entries.ElanInterfaceMac)5 ElanInterface (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.ElanInterface)5 MacEntryBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.forwarding.entries.MacEntryBuilder)5 MacEntryKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.forwarding.entries.MacEntryKey)5 Optional (com.google.common.base.Optional)4 Inject (javax.inject.Inject)4 Singleton (javax.inject.Singleton)4 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)4 ManagedNewTransactionRunner (org.opendaylight.genius.infra.ManagedNewTransactionRunner)4