use of org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface in project netvirt by opendaylight.
the class ShowVpn method doExecute.
@Override
protected Object doExecute() {
Map<String, Integer> vpnNameToConfigInterfaceMap = new HashMap<>();
Map<String, Integer> vpnNameToOperInterfaceMap = new HashMap<>();
if (detail == null) {
showVpn();
Set<String> vpnInstances = new HashSet();
for (VpnInterface vpnInterface : vpnInterfaceConfigList) {
for (VpnInstanceNames vpnInterfaceVpnInstance : vpnInterface.getVpnInstanceNames()) {
String vpnName = vpnInterfaceVpnInstance.getVpnName();
if (vpnName != null) {
vpnInstances.add(vpnName);
}
}
}
for (String routerId : vpnInstances) {
ifPresent = vpnNameToConfigInterfaceMap.get(routerId);
if (ifPresent == null) {
vpnNameToConfigInterfaceMap.put(routerId, 1);
} else {
vpnNameToConfigInterfaceMap.put(routerId, vpnNameToConfigInterfaceMap.get(routerId) + 1);
}
}
for (VpnInterfaceOpDataEntry vpnInterfaceOp : vpnInterfaceOpList) {
ifPresent = vpnNameToOperInterfaceMap.get(vpnInterfaceOp.getVpnInstanceName());
if (ifPresent == null) {
vpnNameToOperInterfaceMap.put(vpnInterfaceOp.getVpnInstanceName(), 1);
} else {
vpnNameToOperInterfaceMap.put(vpnInterfaceOp.getVpnInstanceName(), vpnNameToOperInterfaceMap.get(vpnInterfaceOp.getVpnInstanceName()) + 1);
}
}
session.getConsole().println("-----------------------------------------------------------------------");
session.getConsole().println(String.format(" %s %14s %5s %5s", "VpnInstanceName", "RD", "Config Count", "Oper Count"));
session.getConsole().println("\n-----------------------------------------------------------------------");
for (VpnInstance vpnInstance : vpnInstanceList) {
configCount = 0;
operCount = 0;
Integer count = vpnNameToConfigInterfaceMap.get(vpnInstance.getVpnInstanceName());
if (count != null) {
configCount = vpnNameToConfigInterfaceMap.get(vpnInstance.getVpnInstanceName());
totalConfigCount = totalConfigCount + configCount;
}
count = vpnNameToOperInterfaceMap.get(vpnInstance.getVpnInstanceName());
if (count != null) {
operCount = vpnNameToOperInterfaceMap.get(vpnInstance.getVpnInstanceName());
totalOperCount = totalOperCount + operCount;
}
VpnAfConfig addrFamily = vpnInstance.getIpv4Family() != null ? vpnInstance.getIpv4Family() : vpnInstance.getIpv6Family();
session.getConsole().println(String.format("%-32s %-10s %-10s %-10s", vpnInstance.getVpnInstanceName(), addrFamily.getRouteDistinguisher(), configCount, operCount));
}
session.getConsole().println("-----------------------------------------------------------------------");
session.getConsole().println(String.format("Total Count: %19s %8s", totalConfigCount, totalOperCount));
session.getConsole().println(getshowVpnCLIHelp());
} else {
showVpn();
session.getConsole().println("Present Config VpnInterfaces are:");
for (VpnInterface vpnInterface : vpnInterfaceConfigList) {
if (VpnHelper.doesVpnInterfaceBelongToVpnInstance(detail, vpnInterface.getVpnInstanceNames())) {
session.getConsole().println(vpnInterface.getName());
}
}
session.getConsole().println("Present Oper VpnInterfaces are:");
for (VpnInterfaceOpDataEntry vpnInterfaceOp : vpnInterfaceOpList) {
if (vpnInterfaceOp.getVpnInstanceName().equals(detail)) {
session.getConsole().println(vpnInterfaceOp.getName());
}
}
}
return null;
}
use of org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface in project netvirt by opendaylight.
the class CloudScVpnInterfaceListener method add.
@Override
protected void add(InstanceIdentifier<VpnInterface> key, VpnInterface vpnIfaceAdded) {
for (VpnInstanceNames vpnInstance : vpnIfaceAdded.getVpnInstanceNames()) {
String vpnName = vpnInstance.getVpnName();
if (!vpnInstance.getAssociatedSubnetType().equals(AssociatedSubnetType.V4AndV6Subnets) && !vpnInstance.getAssociatedSubnetType().equals(AssociatedSubnetType.V4Subnet)) {
continue;
}
try {
Optional<VpnToPseudoPortData> optScfInfoForVpn = vpnScHandler.getScfInfoForVpn(vpnName);
if (!optScfInfoForVpn.isPresent()) {
LOG.trace("Vpn {} is not related to ServiceChaining. No further action", vpnName);
return;
}
vpnScHandler.bindScfOnVpnInterface(vpnIfaceAdded.getKey().getName(), optScfInfoForVpn.get().getScfTag());
} catch (ReadFailedException e) {
LOG.error("Error reading the SFC information for VPN {}", vpnName, e);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface in project netvirt by opendaylight.
the class NeutronvpnManager method addSubnetToVpn.
protected void addSubnetToVpn(@Nullable final Uuid vpnId, Uuid subnet, @Nullable final Uuid internetVpnId) {
LOG.debug("addSubnetToVpn: Adding subnet {} to vpn {}", subnet.getValue(), vpnId != null ? vpnId.getValue() : internetVpnId.getValue());
Subnetmap sn = updateSubnetNode(subnet, null, vpnId, internetVpnId);
if (sn == null) {
LOG.error("addSubnetToVpn: subnetmap is null, cannot add subnet {} to VPN {}", subnet.getValue(), vpnId != null ? vpnId.getValue() : internetVpnId.getValue());
return;
}
if (vpnId != null) {
VpnMap vpnMap = neutronvpnUtils.getVpnMap(vpnId);
if (vpnMap == null) {
LOG.error("addSubnetToVpn: No vpnMap for vpnId {}," + " cannot add subnet {} to VPN", vpnId.getValue(), subnet.getValue());
return;
}
final VpnInstance vpnInstance = VpnHelper.getVpnInstance(dataBroker, vpnId.getValue());
LOG.debug("addSubnetToVpn: VpnInstance {}", vpnInstance.toString());
if (isVpnOfTypeL2(vpnInstance)) {
neutronEvpnUtils.updateElanAndVpn(vpnInstance, sn.getNetworkId().getValue(), NeutronEvpnUtils.Operation.ADD);
}
}
if (internetVpnId != null) {
VpnMap vpnMap = neutronvpnUtils.getVpnMap(internetVpnId);
if (vpnMap == null) {
LOG.error("addSubnetToVpn: No vpnMap for InternetVpnId {}, cannot add " + "subnet {} to VPN", internetVpnId.getValue(), subnet.getValue());
return;
}
}
final Uuid internetId = internetVpnId;
// Check if there are ports on this subnet and add corresponding vpn-interfaces
List<Uuid> portList = sn.getPortList();
if (portList != null) {
for (final Uuid portId : portList) {
String vpnInfName = portId.getValue();
VpnInterface vpnIface = VpnHelper.getVpnInterface(dataBroker, vpnInfName);
Port port = neutronvpnUtils.getNeutronPort(portId);
if (port == null) {
LOG.error("addSubnetToVpn: Cannot proceed with addSubnetToVpn for port {} in subnet {} " + "since port is absent in Neutron config DS", portId.getValue(), subnet.getValue());
continue;
}
final Boolean isRouterInterface = port.getDeviceOwner().equals(NeutronConstants.DEVICE_OWNER_ROUTER_INF) ? true : false;
jobCoordinator.enqueueJob("PORT-" + portId.getValue(), () -> singletonList(managedNewTransactionRunner.callWithNewWriteOnlyTransactionAndSubmit(wrtConfigTxn -> {
Adjacencies portAdj = createPortIpAdjacencies(port, isRouterInterface, wrtConfigTxn, sn, vpnIface);
if (vpnIface == null) {
LOG.trace("addSubnetToVpn: create new VpnInterface for Port {}", vpnInfName);
Set<Uuid> listVpn = new HashSet<Uuid>();
if (vpnId != null) {
listVpn.add(vpnId);
}
if (internetId != null) {
listVpn.add(internetId);
}
writeVpnInterfaceToDs(listVpn, vpnInfName, portAdj, isRouterInterface, wrtConfigTxn);
if (sn.getRouterId() != null) {
addToNeutronRouterInterfacesMap(sn.getRouterId(), portId.getValue());
}
} else {
LOG.trace("update VpnInterface for Port {} with adj {}", vpnInfName, portAdj);
if (vpnId != null) {
updateVpnInterfaceWithAdjacencies(vpnId, vpnInfName, portAdj, wrtConfigTxn);
}
if (internetId != null) {
updateVpnInterfaceWithAdjacencies(internetId, vpnInfName, portAdj, wrtConfigTxn);
}
}
})));
}
}
}
use of org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface in project netvirt by opendaylight.
the class NeutronvpnManager method removeVpnFromVpnInterface.
protected void removeVpnFromVpnInterface(Uuid vpnId, Port port, WriteTransaction writeConfigTxn, Subnetmap sm) {
if (vpnId == null || port == null) {
return;
}
String infName = port.getUuid().getValue();
InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
try {
Optional<VpnInterface> optionalVpnInterface = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
if (optionalVpnInterface.isPresent()) {
List<VpnInstanceNames> listVpn = optionalVpnInterface.get().getVpnInstanceNames();
if (listVpn != null && VpnHelper.doesVpnInterfaceBelongToVpnInstance(vpnId.getValue(), listVpn)) {
VpnHelper.removeVpnInterfaceVpnInstanceNamesFromList(vpnId.getValue(), listVpn);
}
VpnInterfaceBuilder vpnIfBuilder = new VpnInterfaceBuilder(optionalVpnInterface.get()).setVpnInstanceNames(listVpn);
Adjacencies adjs = vpnIfBuilder.getAugmentation(Adjacencies.class);
LOG.debug("Updating vpn interface {}", infName);
List<Adjacency> adjacencyList = adjs != null ? adjs.getAdjacency() : new ArrayList<>();
Iterator<Adjacency> adjacencyIter = adjacencyList.iterator();
while (adjacencyIter.hasNext()) {
Adjacency adjacency = adjacencyIter.next();
if (adjacency.getAdjacencyType() == AdjacencyType.PrimaryAdjacency) {
continue;
}
String mipToQuery = adjacency.getIpAddress().split("/")[0];
InstanceIdentifier<LearntVpnVipToPort> id = NeutronvpnUtils.buildLearntVpnVipToPortIdentifier(vpnId.getValue(), mipToQuery);
Optional<LearntVpnVipToPort> optionalVpnVipToPort = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
if (optionalVpnVipToPort.isPresent()) {
LOG.trace("Removing adjacencies from vpninterface {} upon dissociation of router {}", infName, vpnId);
if (listVpn == null || listVpn.isEmpty()) {
adjacencyIter.remove();
}
neutronvpnUtils.removeLearntVpnVipToPort(vpnId.getValue(), mipToQuery);
LOG.trace("Entry for fixedIP {} for port {} on VPN {} removed from VpnPortFixedIPToPortData", mipToQuery, infName, vpnId.getValue());
}
}
List<FixedIps> ips = port.getFixedIps();
for (FixedIps ip : ips) {
String ipValue = String.valueOf(ip.getIpAddress().getValue());
neutronvpnUtils.removeVpnPortFixedIpToPort(vpnId.getValue(), ipValue, writeConfigTxn);
}
if (listVpn == null || listVpn.isEmpty()) {
if (sm != null && sm.getRouterId() != null) {
removeFromNeutronRouterInterfacesMap(sm.getRouterId(), port.getUuid().getValue());
}
deleteVpnInterface(port.getUuid().getValue(), null, /* vpn-id */
writeConfigTxn);
} else {
writeConfigTxn.put(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIfBuilder.build());
}
} else {
LOG.info("removeVpnFromVpnInterface: VPN Interface {} not found", infName);
}
} catch (ReadFailedException ex) {
LOG.error("Update of vpninterface {} failed", infName, ex);
}
}
use of org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface in project netvirt by opendaylight.
the class NeutronvpnManager method createPortIpAdjacencies.
protected Adjacencies createPortIpAdjacencies(Port port, Boolean isRouterInterface, WriteTransaction wrtConfigTxn, Subnetmap sn, VpnInterface vpnIface) {
List<Adjacency> adjList = new ArrayList<>();
if (vpnIface != null) {
adjList = vpnIface.getAugmentation(Adjacencies.class).getAdjacency();
}
String infName = port.getUuid().getValue();
LOG.trace("neutronVpnManager: create config adjacencies for Port: {}", infName);
for (FixedIps ip : port.getFixedIps()) {
String ipValue = String.valueOf(ip.getIpAddress().getValue());
String ipPrefix = ip.getIpAddress().getIpv4Address() != null ? ipValue + "/32" : ipValue + "/128";
if (sn != null && !FibHelper.doesPrefixBelongToSubnet(ipPrefix, sn.getSubnetIp(), false)) {
continue;
}
Adjacency vmAdj = new AdjacencyBuilder().setKey(new AdjacencyKey(ipPrefix)).setIpAddress(ipPrefix).setMacAddress(port.getMacAddress().getValue()).setAdjacencyType(AdjacencyType.PrimaryAdjacency).setSubnetId(ip.getSubnetId()).build();
if (!adjList.contains(vmAdj)) {
adjList.add(vmAdj);
}
Subnetmap snTemp = sn != null ? sn : neutronvpnUtils.getSubnetmap(ip.getSubnetId());
Uuid routerId = snTemp != null ? snTemp.getRouterId() : null;
Uuid vpnId = snTemp != null ? snTemp.getVpnId() : null;
if (vpnId != null) {
neutronvpnUtils.createVpnPortFixedIpToPort(vpnId.getValue(), ipValue, infName, port.getMacAddress().getValue(), isRouterInterface, wrtConfigTxn);
}
if (snTemp != null && snTemp.getInternetVpnId() != null) {
neutronvpnUtils.createVpnPortFixedIpToPort(sn.getInternetVpnId().getValue(), ipValue, infName, port.getMacAddress().getValue(), isRouterInterface, wrtConfigTxn);
}
if (routerId != null) {
Router rtr = neutronvpnUtils.getNeutronRouter(routerId);
if (rtr != null && rtr.getRoutes() != null) {
List<Routes> routeList = rtr.getRoutes();
// create extraroute Adjacence for each ipValue,
// because router can have IPv4 and IPv6 subnet ports, or can have
// more that one IPv4 subnet port or more than one IPv6 subnet port
List<Adjacency> erAdjList = getAdjacencyforExtraRoute(routeList, ipValue);
if (!erAdjList.isEmpty()) {
adjList.addAll(erAdjList);
}
}
}
}
return new AdjacenciesBuilder().setAdjacency(adjList).build();
}
Aggregations