Search in sources :

Example 1 with NeutronvpnService

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.NeutronvpnService in project netvirt by opendaylight.

the class AlivenessMonitorUtils method startArpMonitoring.

public static void startArpMonitoring(MacEntry macEntry, Long arpMonitorProfileId, AlivenessMonitorService alivenessMonitorService, DataBroker dataBroker, INeutronVpnManager neutronVpnService, IInterfaceManager interfaceManager) {
    if (interfaceManager.isExternalInterface(macEntry.getInterfaceName())) {
        LOG.debug("ARP monitoring is currently not supported through external interfaces," + "skipping ARP monitoring from interface {} for IP {} (last known MAC {})", macEntry.getInterfaceName(), macEntry.getIpAddress().getHostAddress(), macEntry.getMacAddress());
        return;
    }
    Optional<IpAddress> gatewayIpOptional = VpnUtil.getGatewayIpAddressFromInterface(macEntry.getInterfaceName(), neutronVpnService);
    if (!gatewayIpOptional.isPresent()) {
        LOG.error("Error while retrieving GatewayIp for interface{}", macEntry.getInterfaceName());
        return;
    }
    final IpAddress gatewayIp = gatewayIpOptional.get();
    Optional<String> gatewayMacOptional = VpnUtil.getGWMacAddressFromInterface(macEntry, gatewayIp, dataBroker);
    if (!gatewayMacOptional.isPresent()) {
        LOG.error("Error while retrieving GatewayMac for interface{}", macEntry.getInterfaceName());
        return;
    }
    final PhysAddress gatewayMac = new PhysAddress(gatewayMacOptional.get());
    if (arpMonitorProfileId == null || arpMonitorProfileId.equals(0L)) {
        Optional<Long> profileIdOptional = allocateProfile(alivenessMonitorService, ArpConstants.FAILURE_THRESHOLD, ArpConstants.ARP_CACHE_TIMEOUT_MILLIS, ArpConstants.MONITORING_WINDOW, EtherTypes.Arp);
        if (!profileIdOptional.isPresent()) {
            LOG.error("Error while allocating Profile Id for alivenessMonitorService");
            return;
        }
        arpMonitorProfileId = profileIdOptional.get();
    }
    IpAddress targetIp = new IpAddress(new Ipv4Address(macEntry.getIpAddress().getHostAddress()));
    MonitorStartInput arpMonitorInput = new MonitorStartInputBuilder().setConfig(new ConfigBuilder().setSource(new SourceBuilder().setEndpointType(getSourceEndPointType(macEntry.getInterfaceName(), gatewayIp, gatewayMac)).build()).setDestination(new DestinationBuilder().setEndpointType(getEndPointIpAddress(targetIp)).build()).setMode(MonitoringMode.OneOne).setProfileId(arpMonitorProfileId).build()).build();
    try {
        Future<RpcResult<MonitorStartOutput>> result = alivenessMonitorService.monitorStart(arpMonitorInput);
        RpcResult<MonitorStartOutput> rpcResult = result.get();
        long monitorId;
        if (rpcResult.isSuccessful()) {
            monitorId = rpcResult.getResult().getMonitorId();
            createOrUpdateInterfaceMonitorIdMap(monitorId, macEntry);
            LOG.trace("Started ARP monitoring with id {}", monitorId);
        } else {
            LOG.warn("RPC Call to start monitoring returned with Errors {}", rpcResult.getErrors());
        }
    } catch (InterruptedException | ExecutionException e) {
        LOG.warn("Exception when starting monitoring", e);
    }
}
Also used : MonitorStartOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorStartOutput) SourceBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.params.SourceBuilder) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) MonitorStartInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorStartInput) DestinationBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.params.DestinationBuilder) ConfigBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.start.input.ConfigBuilder) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) ExecutionException(java.util.concurrent.ExecutionException) MonitorStartInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorStartInputBuilder) PhysAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)

Example 2 with NeutronvpnService

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.NeutronvpnService in project netvirt by opendaylight.

the class NatUtil method removeSnatEntriesForPort.

public static void removeSnatEntriesForPort(DataBroker dataBroker, NaptManager naptManager, IMdsalApiManager mdsalManager, NeutronvpnService neutronVpnService, String interfaceName, String routerName) {
    Uint32 routerId = NatUtil.getVpnId(dataBroker, routerName);
    if (routerId == NatConstants.INVALID_ID) {
        LOG.error("removeSnatEntriesForPort: routerId not found for routername {}", routerName);
        return;
    }
    Uint64 naptSwitch = getPrimaryNaptfromRouterName(dataBroker, routerName);
    if (naptSwitch == null || naptSwitch.equals(Uint64.ZERO)) {
        LOG.error("removeSnatEntriesForPort: NaptSwitch is not elected for router {}" + "with Id {}", routerName, routerId);
        return;
    }
    // getInternalIp for port
    List<String> fixedIps = getFixedIpsForPort(neutronVpnService, interfaceName);
    if (fixedIps == null) {
        LOG.error("removeSnatEntriesForPort: Internal Ips not found for InterfaceName {} in router {} with id {}", interfaceName, routerName, routerId);
        return;
    }
    List<ProtocolTypes> protocolTypesList = getPortocolList();
    for (String internalIp : fixedIps) {
        LOG.debug("removeSnatEntriesForPort: Internal Ip retrieved for interface {} is {} in router with Id {}", interfaceName, internalIp, routerId);
        for (ProtocolTypes protocol : protocolTypesList) {
            List<Uint16> portList = NatUtil.getInternalIpPortListInfo(dataBroker, routerId, internalIp, protocol);
            if (portList != null) {
                for (Uint16 portnum : portList) {
                    // build and remove the flow in outbound table
                    removeNatFlow(mdsalManager, naptSwitch, NwConstants.OUTBOUND_NAPT_TABLE, routerId, internalIp, portnum.toJava(), protocol.getName());
                    // build and remove the flow in inboundtable
                    removeNatFlow(mdsalManager, naptSwitch, NwConstants.INBOUND_NAPT_TABLE, routerId, internalIp, portnum.toJava(), protocol.getName());
                    // Get the external IP address and the port from the model
                    NAPTEntryEvent.Protocol proto = protocol.toString().equals(ProtocolTypes.TCP.toString()) ? NAPTEntryEvent.Protocol.TCP : NAPTEntryEvent.Protocol.UDP;
                    IpPortExternal ipPortExternal = NatUtil.getExternalIpPortMap(dataBroker, routerId, internalIp, String.valueOf(portnum.toJava()), proto);
                    if (ipPortExternal == null) {
                        LOG.error("removeSnatEntriesForPort: Mapping for internalIp {} " + "with port {} is not found in " + "router with Id {}", internalIp, portnum, routerId);
                        return;
                    }
                    String externalIpAddress = ipPortExternal.getIpAddress();
                    String internalIpPort = internalIp + ":" + portnum.toJava();
                    // delete the entry from IntExtIpPortMap DS
                    naptManager.removeFromIpPortMapDS(routerId, internalIpPort, proto);
                    naptManager.removePortFromPool(internalIpPort, externalIpAddress);
                }
            } else {
                LOG.debug("removeSnatEntriesForPort: No {} session for interface {} with internalIP {} " + "in router with id {}", protocol, interfaceName, internalIp, routerId);
            }
        }
        // delete the entry from SnatIntIpPortMap DS
        LOG.debug("removeSnatEntriesForPort: Removing InternalIp :{} of router {} from snatint-ip-port-map", internalIp, routerId);
        naptManager.removeFromSnatIpPortDS(routerId, internalIp);
    }
}
Also used : ProtocolTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProtocolTypes) Uint16(org.opendaylight.yangtools.yang.common.Uint16) IpPortExternal(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.intext.ip.protocol.type.ip.port.map.IpPortExternal) Uint32(org.opendaylight.yangtools.yang.common.Uint32) Uint64(org.opendaylight.yangtools.yang.common.Uint64)

Example 3 with NeutronvpnService

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.NeutronvpnService in project netvirt by opendaylight.

the class NatUtil method getFixedIpsForPort.

private static List<String> getFixedIpsForPort(NeutronvpnService neutronVpnService, String interfname) {
    LOG.debug("getFixedIpsForPort: getFixedIpsForPort method is called for interface {}", interfname);
    try {
        Future<RpcResult<GetFixedIPsForNeutronPortOutput>> result = neutronVpnService.getFixedIPsForNeutronPort(new GetFixedIPsForNeutronPortInputBuilder().setPortId(new Uuid(interfname)).build());
        RpcResult<GetFixedIPsForNeutronPortOutput> rpcResult = result.get();
        if (!rpcResult.isSuccessful()) {
            LOG.error("getFixedIpsForPort: RPC Call to GetFixedIPsForNeutronPortOutput returned with Errors {}", rpcResult.getErrors());
        } else {
            return rpcResult.getResult().getFixedIPs();
        }
    } catch (InterruptedException | ExecutionException | NullPointerException ex) {
        LOG.error("getFixedIpsForPort: Exception while receiving fixedIps for port {}", interfname, ex);
    }
    return null;
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) GetFixedIPsForNeutronPortOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.GetFixedIPsForNeutronPortOutput) ExecutionException(java.util.concurrent.ExecutionException) GetFixedIPsForNeutronPortInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.GetFixedIPsForNeutronPortInputBuilder)

Example 4 with NeutronvpnService

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.NeutronvpnService in project netvirt by opendaylight.

the class VpnUtil method getGatewayIpAddressFromInterface.

public Optional<IpAddress> getGatewayIpAddressFromInterface(MacEntry macEntry) {
    Optional<IpAddress> gatewayIp = Optional.empty();
    String srcInterface = macEntry.getInterfaceName();
    InetAddress hiddenIp = macEntry.getIpAddress();
    if (neutronVpnService != null) {
        // TODO(Gobinath): Need to fix this as assuming port will belong to only one Subnet would be incorrect"
        Port port = neutronVpnService.getNeutronPort(srcInterface);
        if (port != null && port.getFixedIps() != null) {
            for (FixedIps portIp : port.getFixedIps().values()) {
                if (doesInterfaceAndHiddenIpAddressTypeMatch(hiddenIp, portIp)) {
                    gatewayIp = Optional.of(neutronVpnService.getNeutronSubnet(portIp.getSubnetId()).getGatewayIp());
                    break;
                }
            }
        }
    } else {
        LOG.error("getGatewayIpAddressFromInterface: neutron vpn service is not configured." + " Failed for interface {}.", srcInterface);
    }
    return gatewayIp;
}
Also used : VpnPortipToPort(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.neutron.vpn.portip.port.data.VpnPortipToPort) LearntVpnVipToPort(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPort) Port(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) FixedIps(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps) InetAddress(java.net.InetAddress)

Example 5 with NeutronvpnService

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.NeutronvpnService in project netvirt by opendaylight.

the class InterVpnLinkLocatorTest method setUp.

@Before
public void setUp() throws Exception {
    dataBroker = getDataBroker();
    vpnUtil = new VpnUtil(dataBroker, idManager, fibManager, bgpManager, lockManager, neutronVpnService, mdsalManager, jobCoordinator, interfaceManager, ifmRpcService);
    // Creating both empty containers: InterVpnLinks and InterVpnLinkStates
    WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
    writeTx.merge(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.create(InterVpnLinks.class), new InterVpnLinksBuilder().setInterVpnLink(Collections.emptyList()).build());
    writeTx.merge(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.create(InterVpnLinkStates.class), new InterVpnLinkStatesBuilder().setInterVpnLinkState(Collections.emptyList()).build());
    writeTx.commit().get();
    interVpnLinkCache = new InterVpnLinkCacheImpl(dataBroker);
    interVpnLinkCache.initialFeed();
    // Prepare
    populateL3Vpns(dataBroker, L3VpnTestCatalog.ALL_VPNS);
    InterVpnLinkTestCatalog.populateIvpnLinks(dataBroker, ALL_IVPN_LINKS);
    for (InterVpnLinkDataComposite ivl : ALL_IVPN_LINKS) {
        interVpnLinkCache.addInterVpnLinkToCaches(ivl.getInterVpnLinkConfig());
        interVpnLinkCache.addInterVpnLinkStateToCaches(ivl.getInterVpnLinkState());
    }
    // SUT
    sut = new InterVpnLinkLocator(dataBroker, interVpnLinkCache, vpnUtil);
}
Also used : WriteTransaction(org.opendaylight.mdsal.binding.api.WriteTransaction) InterVpnLinkStates(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.InterVpnLinkStates) VpnUtil(org.opendaylight.netvirt.vpnmanager.VpnUtil) InterVpnLinks(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.InterVpnLinks) InterVpnLinksBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.InterVpnLinksBuilder) InterVpnLinkStatesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.InterVpnLinkStatesBuilder) InterVpnLinkDataComposite(org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkDataComposite) Before(org.junit.Before)

Aggregations

InetAddress (java.net.InetAddress)2 ExecutionException (java.util.concurrent.ExecutionException)2 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)2 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)2 Uint64 (org.opendaylight.yangtools.yang.common.Uint64)2 UnknownHostException (java.net.UnknownHostException)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 PreDestroy (javax.annotation.PreDestroy)1 Inject (javax.inject.Inject)1 Singleton (javax.inject.Singleton)1 Before (org.junit.Before)1 MDSALUtil (org.opendaylight.genius.mdsalutil.MDSALUtil)1 IMdsalApiManager (org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager)1 Executors (org.opendaylight.infrautils.utils.concurrent.Executors)1 LoggingFutures (org.opendaylight.infrautils.utils.concurrent.LoggingFutures)1 DataBroker (org.opendaylight.mdsal.binding.api.DataBroker)1 WriteTransaction (org.opendaylight.mdsal.binding.api.WriteTransaction)1 CONFIGURATION (org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION)1 OPERATIONAL (org.opendaylight.mdsal.binding.util.Datastore.OPERATIONAL)1 ManagedNewTransactionRunner (org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner)1