Search in sources :

Example 1 with VpnPortipToPortKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.neutron.vpn.portip.port.data.VpnPortipToPortKey in project netvirt by opendaylight.

the class NeutronvpnUtils method createVpnPortFixedIpToPort.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
protected void createVpnPortFixedIpToPort(String vpnName, String fixedIp, String portName, String macAddress, boolean isSubnetIp, WriteTransaction writeConfigTxn) {
    InstanceIdentifier<VpnPortipToPort> id = NeutronvpnUtils.buildVpnPortipToPortIdentifier(vpnName, fixedIp);
    VpnPortipToPortBuilder builder = new VpnPortipToPortBuilder().setKey(new VpnPortipToPortKey(fixedIp, vpnName)).setVpnName(vpnName).setPortFixedip(fixedIp).setPortName(portName).setMacAddress(macAddress).setSubnetIp(isSubnetIp);
    try {
        if (writeConfigTxn != null) {
            writeConfigTxn.put(LogicalDatastoreType.CONFIGURATION, id, builder.build());
        } else {
            MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id, builder.build());
        }
        LOG.trace("Neutron port with fixedIp: {}, vpn {}, interface {}, mac {}, isSubnetIp {} added to " + "VpnPortipToPort DS", fixedIp, vpnName, portName, macAddress, isSubnetIp);
    } catch (Exception e) {
        LOG.error("Failure while creating VPNPortFixedIpToPort map for vpn {} - fixedIP {}", vpnName, fixedIp, e);
    }
}
Also used : VpnPortipToPort(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.neutron.vpn.portip.port.data.VpnPortipToPort) VpnPortipToPortKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.neutron.vpn.portip.port.data.VpnPortipToPortKey) VpnPortipToPortBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.neutron.vpn.portip.port.data.VpnPortipToPortBuilder) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)

Example 2 with VpnPortipToPortKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.neutron.vpn.portip.port.data.VpnPortipToPortKey in project netvirt by opendaylight.

the class NatUtil method getSubnetGwMac.

public static String getSubnetGwMac(DataBroker broker, Uuid subnetId, String vpnName) {
    if (subnetId == null) {
        LOG.error("getSubnetGwMac : subnetID is null");
        return null;
    }
    InstanceIdentifier<Subnet> subnetInst = InstanceIdentifier.create(Neutron.class).child(Subnets.class).child(Subnet.class, new SubnetKey(subnetId));
    Optional<Subnet> subnetOpt = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker, LogicalDatastoreType.CONFIGURATION, subnetInst);
    if (!subnetOpt.isPresent()) {
        LOG.error("getSubnetGwMac : unable to obtain Subnet for id : {}", subnetId);
        return null;
    }
    IpAddress gatewayIp = subnetOpt.get().getGatewayIp();
    if (gatewayIp == null) {
        LOG.warn("getSubnetGwMac : No GW ip found for subnet {}", subnetId.getValue());
        return null;
    }
    InstanceIdentifier<VpnPortipToPort> portIpInst = InstanceIdentifier.builder(NeutronVpnPortipPortData.class).child(VpnPortipToPort.class, new VpnPortipToPortKey(gatewayIp.getIpv4Address().getValue(), vpnName)).build();
    Optional<VpnPortipToPort> portIpToPortOpt = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker, LogicalDatastoreType.CONFIGURATION, portIpInst);
    if (portIpToPortOpt.isPresent()) {
        return portIpToPortOpt.get().getMacAddress();
    }
    InstanceIdentifier<LearntVpnVipToPort> learntIpInst = InstanceIdentifier.builder(LearntVpnVipToPortData.class).child(LearntVpnVipToPort.class, new LearntVpnVipToPortKey(gatewayIp.getIpv4Address().getValue(), vpnName)).build();
    Optional<LearntVpnVipToPort> learntIpToPortOpt = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker, LogicalDatastoreType.OPERATIONAL, learntIpInst);
    if (learntIpToPortOpt.isPresent()) {
        return learntIpToPortOpt.get().getMacAddress();
    }
    LOG.info("getSubnetGwMac : No resolution was found to GW ip {} in subnet {}", gatewayIp, subnetId.getValue());
    return null;
}
Also used : VpnPortipToPort(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.neutron.vpn.portip.port.data.VpnPortipToPort) ExternalSubnets(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalSubnets) Subnets(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.Subnets) SubnetKey(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.SubnetKey) VpnPortipToPortKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.neutron.vpn.portip.port.data.VpnPortipToPortKey) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) LearntVpnVipToPort(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPort) Subnet(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet) LearntVpnVipToPortKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPortKey)

Example 3 with VpnPortipToPortKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.neutron.vpn.portip.port.data.VpnPortipToPortKey in project netvirt by opendaylight.

the class ShowVpnIpToPort method doExecute.

@Override
@SuppressWarnings("checkstyle:RegexpSinglelineJava")
protected Object doExecute() throws Exception {
    if (vpnName == null && portFixedIp == null) {
        getNeutronVpnPort();
        getLearntVpnVipPort();
        System.out.println(vpnPortipToPortList.size() + " Entries are present: ");
        System.out.println("-----------------------------------------------------------------------");
        System.out.println(String.format("             %s   %24s   %20s   %32s", "VpnName", "IPAddress", "MacAddress", "Port"));
        System.out.println("-----------------------------------------------------------------------");
        for (VpnPortipToPort vpnPortipToPort : vpnPortipToPortList) {
            System.out.println(String.format("  %-32s  %-16s  %-16s  %-32s", vpnPortipToPort.getVpnName(), vpnPortipToPort.getPortFixedip(), vpnPortipToPort.getMacAddress(), vpnPortipToPort.getPortName()));
        }
        for (LearntVpnVipToPort learntVpnVipToPort : vpnVipToPortList) {
            System.out.println(String.format("* %-32s  %-16s  %-16s  %-32s", learntVpnVipToPort.getVpnName(), learntVpnVipToPort.getPortFixedip(), learntVpnVipToPort.getMacAddress(), learntVpnVipToPort.getPortName()));
        }
        System.out.println("\n * prefixed entries are Learned.");
        System.out.println("\n" + getshowVpnCLIHelp());
    } else if (portFixedIp == null || vpnName == null) {
        System.out.println("Insufficient arguments" + "\nCorrect Usage : neutronvpn-port-show [<vpnName> <portFixedIp>]");
    } else {
        InstanceIdentifier<VpnPortipToPort> id = InstanceIdentifier.builder(NeutronVpnPortipPortData.class).child(VpnPortipToPort.class, new VpnPortipToPortKey(portFixedIp, vpnName)).build();
        Optional<VpnPortipToPort> vpnPortipToPortData = syncReadOptional(dataBroker, CONFIGURATION, id);
        if (vpnPortipToPortData.isPresent()) {
            VpnPortipToPort data = vpnPortipToPortData.get();
            System.out.println("\n----------" + "---------------------------------------------------------------------------------");
            System.out.println("VpnName:   " + data.getVpnName() + "\nIPAddress: " + data.getPortFixedip() + "\nMacAddress: " + data.getMacAddress() + "\nPort: " + data.getPortName());
            System.out.println("\n----------" + "---------------------------------------------------------------------------------");
        } else {
            InstanceIdentifier<LearntVpnVipToPort> learntId = InstanceIdentifier.builder(LearntVpnVipToPortData.class).child(LearntVpnVipToPort.class, new LearntVpnVipToPortKey(portFixedIp, vpnName)).build();
            Optional<LearntVpnVipToPort> learntVpnVipToPortData = syncReadOptional(dataBroker, OPERATIONAL, learntId);
            if (!learntVpnVipToPortData.isPresent()) {
                System.out.println("Data not available");
                return null;
            }
            LearntVpnVipToPort data = learntVpnVipToPortData.get();
            System.out.println("\n----------" + "---------------------------------------------------------------------------------");
            System.out.println("VpnName: * " + data.getVpnName() + "\nIPAddress: " + data.getPortFixedip() + "\nMacAddress: " + data.getMacAddress() + "\nPort: " + data.getPortName());
            System.out.println("\n----------" + "---------------------------------------------------------------------------------");
        }
        System.out.println("\n" + getshowVpnCLIHelp());
    }
    return null;
}
Also used : SingleTransactionDataBroker.syncReadOptional(org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker.syncReadOptional) Optional(com.google.common.base.Optional) VpnPortipToPort(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.neutron.vpn.portip.port.data.VpnPortipToPort) VpnPortipToPortKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.neutron.vpn.portip.port.data.VpnPortipToPortKey) NeutronVpnPortipPortData(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.NeutronVpnPortipPortData) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) LearntVpnVipToPort(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPort) LearntVpnVipToPortData(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.LearntVpnVipToPortData) LearntVpnVipToPortKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPortKey)

Aggregations

VpnPortipToPort (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.neutron.vpn.portip.port.data.VpnPortipToPort)3 VpnPortipToPortKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.neutron.vpn.portip.port.data.VpnPortipToPortKey)3 LearntVpnVipToPort (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPort)2 LearntVpnVipToPortKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPortKey)2 Optional (com.google.common.base.Optional)1 UnknownHostException (java.net.UnknownHostException)1 ExecutionException (java.util.concurrent.ExecutionException)1 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)1 SingleTransactionDataBroker.syncReadOptional (org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker.syncReadOptional)1 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)1 LearntVpnVipToPortData (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.LearntVpnVipToPortData)1 ExternalSubnets (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalSubnets)1 NeutronVpnPortipPortData (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.NeutronVpnPortipPortData)1 VpnPortipToPortBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.neutron.vpn.portip.port.data.VpnPortipToPortBuilder)1 Subnets (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.Subnets)1 Subnet (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet)1 SubnetKey (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.SubnetKey)1 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)1