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);
}
}
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;
}
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;
}
Aggregations