Search in sources :

Example 6 with Port

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.Port in project netvirt by opendaylight.

the class SubnetRouteInterfaceStateChangeListener method remove.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
@Override
protected void remove(InstanceIdentifier<Interface> identifier, Interface intrf) {
    try {
        if (L2vlan.class.equals(intrf.getType())) {
            LOG.trace("SubnetRouteInterfaceListener remove: Received interface {} down event", intrf);
            List<Uuid> subnetIdList = getSubnetId(intrf);
            if (subnetIdList.isEmpty()) {
                LOG.trace("SubnetRouteInterfaceListener remove: Port {} doesn't exist in configDS", intrf.getName());
                return;
            }
            for (Uuid subnetId : subnetIdList) {
                jobCoordinator.enqueueJob("SUBNETROUTE-" + subnetId, () -> {
                    String interfaceName = intrf.getName();
                    BigInteger dpnId = BigInteger.ZERO;
                    LOG.info("{} remove: Received port DOWN event for interface {} in subnet {} ", LOGGING_PREFIX, interfaceName, subnetId);
                    try {
                        dpnId = InterfaceUtils.getDpIdFromInterface(intrf);
                    } catch (Exception e) {
                        LOG.error("{} remove: Unable to retrieve dpnId for interface {} in subnet {}. " + "Fetching from vpn interface itself", LOGGING_PREFIX, intrf.getName(), subnetId, e);
                    }
                    InstanceIdentifier<VpnInterface> id = VpnUtil.getVpnInterfaceIdentifier(interfaceName);
                    Optional<VpnInterface> cfgVpnInterface = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
                    List<ListenableFuture<Void>> futures = new ArrayList<>();
                    if (!cfgVpnInterface.isPresent()) {
                        return futures;
                    }
                    boolean interfaceDownEligible = false;
                    for (VpnInstanceNames vpnInterfaceVpnInstance : cfgVpnInterface.get().getVpnInstanceNames()) {
                        String vpnName = vpnInterfaceVpnInstance.getVpnName();
                        InstanceIdentifier<VpnInterfaceOpDataEntry> idOper = VpnUtil.getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
                        Optional<VpnInterfaceOpDataEntry> optVpnInterface = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, idOper);
                        if (optVpnInterface.isPresent()) {
                            BigInteger dpnIdLocal = dpnId;
                            if (dpnIdLocal.equals(BigInteger.ZERO)) {
                                dpnIdLocal = optVpnInterface.get().getDpnId();
                            }
                            if (!dpnIdLocal.equals(BigInteger.ZERO)) {
                                interfaceDownEligible = true;
                                break;
                            }
                        }
                    }
                    if (interfaceDownEligible) {
                        vpnSubnetRouteHandler.onInterfaceDown(dpnId, intrf.getName(), subnetId);
                    }
                    return futures;
                });
            }
        }
        LOG.info("{} remove: Processed interface {} down event in ", LOGGING_PREFIX, intrf.getName());
    } catch (Exception e) {
        LOG.error("{} remove: Exception observed in handling deletion of VPN Interface {}.", LOGGING_PREFIX, intrf.getName(), e);
    }
}
Also used : ArrayList(java.util.ArrayList) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) VpnInterface(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface) VpnInstanceNames(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.vpn._interface.VpnInstanceNames) BigInteger(java.math.BigInteger) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) VpnInterfaceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry)

Example 7 with Port

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.Port in project netvirt by opendaylight.

the class SubnetRoutePacketInHandler method onPacketReceived.

@Override
public void onPacketReceived(PacketReceived notification) {
    short tableId = notification.getTableId().getValue();
    LOG.trace("{} onPacketReceived: Packet punted from table {}", LOGGING_PREFIX, tableId);
    byte[] data = notification.getPayload();
    if (notification.getMatch() == null || notification.getMatch().getMetadata() == null) {
        LOG.error("{} onPacketReceived: Received from table {} where the match or metadata are null", LOGGING_PREFIX, tableId);
        return;
    }
    BigInteger metadata = notification.getMatch().getMetadata().getMetadata();
    Ethernet res = new Ethernet();
    if (tableId == NwConstants.L3_SUBNET_ROUTE_TABLE) {
        LOG.trace("{} onPacketReceived: Some packet received as {}", LOGGING_PREFIX, notification);
        try {
            res.deserialize(data, 0, data.length * NetUtils.NUM_BITS_IN_A_BYTE);
        } catch (PacketException e) {
            LOG.error("{} onPacketReceived: Failed to decode Packet ", LOGGING_PREFIX, e);
            VpnManagerCounters.subnet_route_packet_failed.inc();
            return;
        }
        try {
            Packet pkt = res.getPayload();
            if (pkt instanceof IPv4) {
                IPv4 ipv4 = (IPv4) pkt;
                byte[] srcIp = Ints.toByteArray(ipv4.getSourceAddress());
                byte[] dstIp = Ints.toByteArray(ipv4.getDestinationAddress());
                String dstIpStr = NWUtil.toStringIpAddress(dstIp);
                String srcIpStr = NWUtil.toStringIpAddress(srcIp);
                // It is an ARP request on a configured VPN. So we must
                // attempt to respond.
                long vpnId = MetaDataUtil.getVpnIdFromMetadata(metadata);
                LOG.info("{} onPacketReceived: Processing IPv4 Packet received with Source IP {} and Target IP {}" + " and vpnId {}", LOGGING_PREFIX, srcIpStr, dstIpStr, vpnId);
                Optional<VpnIds> vpnIdsOptional = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, VpnUtil.getVpnIdToVpnInstanceIdentifier(vpnId));
                if (!vpnIdsOptional.isPresent()) {
                    // Donot trigger subnetroute logic for packets from
                    // unknown VPNs
                    VpnManagerCounters.subnet_route_packet_ignored.inc();
                    LOG.info("{} onPacketReceived: Ignoring IPv4 packet with destination Ip {} and source Ip {}" + " as it came on unknown VPN with ID {}", LOGGING_PREFIX, dstIpStr, srcIpStr, vpnId);
                    return;
                }
                String vpnIdVpnInstanceName = vpnIdsOptional.get().getVpnInstanceName();
                if (VpnUtil.getNeutronPortFromVpnPortFixedIp(dataBroker, vpnIdVpnInstanceName, dstIpStr) != null) {
                    VpnManagerCounters.subnet_route_packet_ignored.inc();
                    LOG.info("{} onPacketReceived: IPv4 Packet received with Target IP {} source IP {} vpnId {} " + "is a valid Neutron port,ignoring subnet route processing", LOGGING_PREFIX, dstIpStr, srcIp, vpnId);
                    return;
                }
                if (VpnUtil.getLearntVpnVipToPort(dataBroker, vpnIdVpnInstanceName, dstIpStr) != null) {
                    VpnManagerCounters.subnet_route_packet_ignored.inc();
                    LOG.info("{} onPacketReceived: IPv4 Packet received with Target IP {} source Ip {} vpnId {}" + " is an already discovered IPAddress, ignoring subnet route processing", LOGGING_PREFIX, dstIpStr, srcIp, vpnId);
                    return;
                }
                long elanTag = MetaDataUtil.getElanTagFromMetadata(metadata);
                if (elanTag == 0L) {
                    VpnManagerCounters.subnet_route_packet_failed.inc();
                    LOG.error("{} onPacketReceived: elanTag value from metadata found to be 0, for IPv4 " + " Packet received with Target IP {} src Ip {} vpnId {}", LOGGING_PREFIX, dstIpStr, srcIp, vpnId);
                    return;
                }
                if (!vpnIdsOptional.get().isExternalVpn()) {
                    handleInternalVpnSubnetRoutePacket(metadata, dstIp, srcIpStr, dstIpStr, ipv4.getDestinationAddress(), vpnIdVpnInstanceName, elanTag);
                    return;
                }
                byte[] srcMac = res.getSourceMACAddress();
                handleBgpVpnSubnetRoute(ipv4, srcMac, dstIp, dstIpStr, srcIpStr, elanTag);
            }
        } catch (UnknownHostException | InterruptedException | ExecutionException ex) {
            // Failed to handle packet
            VpnManagerCounters.subnet_route_packet_failed.inc();
            LOG.error("{} onPacketReceived: Failed to handle subnetroute packet.", LOGGING_PREFIX, ex);
        }
        return;
    }
// All Arp responses learning for invisble IPs is handled by
// ArpNotificationHandler
}
Also used : Packet(org.opendaylight.openflowplugin.libraries.liblldp.Packet) UnknownHostException(java.net.UnknownHostException) IPv4(org.opendaylight.genius.mdsalutil.packet.IPv4) PacketException(org.opendaylight.openflowplugin.libraries.liblldp.PacketException) Ethernet(org.opendaylight.genius.mdsalutil.packet.Ethernet) BigInteger(java.math.BigInteger) VpnIds(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.id.to.vpn.instance.VpnIds) ExecutionException(java.util.concurrent.ExecutionException)

Example 8 with Port

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.Port in project netvirt by opendaylight.

the class AclMatches method addIpProtocolMatch.

private void addIpProtocolMatch(AceIp aceIp) {
    // Match on IP
    setIpv4EtherType();
    IpMatchBuilder ipMatch = new IpMatchBuilder();
    ipMatch.setIpProtocol(aceIp.getProtocol());
    matchBuilder.setIpMatch(mergeIpMatch(matchBuilder, ipMatch));
    // TODO Ranges are not supported yet
    int srcPort = 0;
    if (aceIp.getSourcePortRange() != null && aceIp.getSourcePortRange().getLowerPort() != null) {
        srcPort = aceIp.getSourcePortRange().getLowerPort().getValue();
    }
    int dstPort = 0;
    if (aceIp.getDestinationPortRange() != null && aceIp.getDestinationPortRange().getLowerPort() != null) {
        dstPort = aceIp.getDestinationPortRange().getLowerPort().getValue();
    }
    // Match on a TCP/UDP src/dst port
    if (aceIp.getProtocol() == IPProtocols.TCP.shortValue()) {
        TcpMatchBuilder tcpMatch = new TcpMatchBuilder();
        if (srcPort != 0) {
            tcpMatch.setTcpSourcePort(new PortNumber(srcPort));
        }
        if (dstPort != 0) {
            tcpMatch.setTcpDestinationPort(new PortNumber(dstPort));
        }
        if (srcPort != 0 || dstPort != 0) {
            matchBuilder.setLayer4Match(tcpMatch.build());
        }
    } else if (aceIp.getProtocol() == IPProtocols.UDP.shortValue()) {
        UdpMatchBuilder udpMatch = new UdpMatchBuilder();
        if (srcPort != 0) {
            udpMatch.setUdpSourcePort(new PortNumber(srcPort));
        }
        if (dstPort != 0) {
            udpMatch.setUdpDestinationPort(new PortNumber(dstPort));
        }
        if (srcPort != 0 || dstPort != 0) {
            matchBuilder.setLayer4Match(udpMatch.build());
        }
    }
}
Also used : IpMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder) TcpMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder) PortNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber) UdpMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder)

Example 9 with Port

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.Port in project netvirt by opendaylight.

the class NetvirtProviderTest method getLogicalInterfacesFromNeutronNetwork.

@Test
public void getLogicalInterfacesFromNeutronNetwork() {
    // Network doesnt exist
    NeutronNetworkBuilder nwBuilder = new NeutronNetworkBuilder();
    nwBuilder.setNetworkUuid(NW_UUID_NOEXIST_STR);
    List<String> interfaces = netvirtProvider.getLogicalInterfacesFromNeutronNetwork(nwBuilder.build());
    assertTrue(interfaces.isEmpty());
    // Network exists, subnet list empty
    createNetworkMap(NW_UUID_STR);
    nwBuilder = new NeutronNetworkBuilder();
    nwBuilder.setNetworkUuid(NW_UUID_STR);
    interfaces = netvirtProvider.getLogicalInterfacesFromNeutronNetwork(nwBuilder.build());
    assertTrue(interfaces.isEmpty());
    // Network exists, subnet does not exist
    createNetworkMap(NW_UUID_STR, SUBNET_UUID_STR, false, EMPTY_STR);
    nwBuilder = new NeutronNetworkBuilder();
    nwBuilder.setNetworkUuid(NW_UUID_STR);
    interfaces = netvirtProvider.getLogicalInterfacesFromNeutronNetwork(nwBuilder.build());
    assertTrue(interfaces.isEmpty());
    // Network exists, subnet exists, no ports
    createNetworkMap(NW_UUID_STR, SUBNET_UUID_STR, true, EMPTY_STR);
    nwBuilder = new NeutronNetworkBuilder();
    nwBuilder.setNetworkUuid(NW_UUID_STR);
    interfaces = netvirtProvider.getLogicalInterfacesFromNeutronNetwork(nwBuilder.build());
    assertTrue(interfaces.isEmpty());
    // Network exists, subnet exists, port exists
    createNetworkMap(NW_UUID_STR, SUBNET_UUID_STR, true, PORT_UUID_STR);
    nwBuilder = new NeutronNetworkBuilder();
    nwBuilder.setNetworkUuid(NW_UUID_STR);
    interfaces = netvirtProvider.getLogicalInterfacesFromNeutronNetwork(nwBuilder.build());
    assertFalse(interfaces.isEmpty());
}
Also used : NeutronNetworkBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.sfc.acl.rev150105.NeutronNetworkBuilder) Test(org.junit.Test) ConstantSchemaAbstractDataBrokerTest(org.opendaylight.controller.md.sal.binding.test.ConstantSchemaAbstractDataBrokerTest)

Example 10 with Port

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.Port in project netvirt by opendaylight.

the class StatisticsImpl method getNodeConnectorCounters.

@Override
@SuppressWarnings("checkstyle:illegalCatch")
public Future<RpcResult<GetNodeConnectorCountersOutput>> getNodeConnectorCounters(GetNodeConnectorCountersInput input) {
    String portId = input.getPortId();
    LOG.trace("getting port counters of port {}", portId);
    Interface interfaceState = InterfaceUtils.getInterfaceStateFromOperDS(db, portId);
    if (interfaceState == null) {
        LOG.warn("trying to get counters for non exist port {}", portId);
        return RpcResultBuilder.<GetNodeConnectorCountersOutput>failed().buildFuture();
    }
    BigInteger dpId = InterfaceUtils.getDpIdFromInterface(interfaceState);
    if (interfaceState.getLowerLayerIf() == null || interfaceState.getLowerLayerIf().isEmpty()) {
        LOG.warn("Lower layer if wasn't found for port {}", portId);
        return RpcResultBuilder.<GetNodeConnectorCountersOutput>failed().buildFuture();
    }
    String portNumber = interfaceState.getLowerLayerIf().get(0);
    portNumber = portNumber.split(":")[2];
    List<CounterResult> counterResults = new ArrayList<>();
    try {
        if (!getNodeConnectorResult(counterResults, dpId, portNumber)) {
            StatisticsPluginImplCounters.failed_getting_node_connector_counters.inc();
            return RpcResultBuilder.<GetNodeConnectorCountersOutput>failed().withError(ErrorType.APPLICATION, "failed to get port counters").buildFuture();
        }
    } catch (RuntimeException e) {
        LOG.warn("failed to get counter result for port {}", portId, e);
    }
    GetNodeConnectorCountersOutputBuilder gpcob = new GetNodeConnectorCountersOutputBuilder();
    gpcob.setCounterResult(counterResults);
    return RpcResultBuilder.success(gpcob.build()).buildFuture();
}
Also used : ArrayList(java.util.ArrayList) GetNodeConnectorCountersOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.GetNodeConnectorCountersOutput) BigInteger(java.math.BigInteger) Interface(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface) CounterResult(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.result.CounterResult) GetNodeConnectorCountersOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.GetNodeConnectorCountersOutputBuilder)

Aggregations

ArrayList (java.util.ArrayList)124 Test (org.junit.Test)110 BigInteger (java.math.BigInteger)106 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)104 ByteBuf (io.netty.buffer.ByteBuf)57 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)44 Port (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port)44 List (java.util.List)42 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)41 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)41 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)40 PortNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber)38 NodeConnectorId (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId)37 ExecutionException (java.util.concurrent.ExecutionException)33 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)32 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)29 Logger (org.slf4j.Logger)29 LoggerFactory (org.slf4j.LoggerFactory)29 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)28 FixedIps (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps)27