use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.AdjacenciesBuilder in project netvirt by opendaylight.
the class CoeUtils method createPortIpAdjacencies.
static Adjacencies createPortIpAdjacencies(Pods pod, String interfaceName, String macAddress, Boolean isRouterInterface) {
List<Adjacency> adjList = new ArrayList<>();
LOG.trace("create config adjacencies for Port: {}", interfaceName);
IpAddress ip = pod.getInterface().get(0).getIpAddress();
String ipValue = ip.getIpv4Address() != null ? ip.getIpv4Address().getValue() : ip.getIpv6Address().getValue();
String ipPrefix = ip.getIpv4Address() != null ? ipValue + "/32" : ipValue + "/128";
String hostIp = new String(pod.getHostIpAddress().getValue());
UUID subnetId = UUID.nameUUIDFromBytes(hostIp.getBytes(StandardCharsets.UTF_8));
String gatewayIP = ipValue.replaceFirst("\\d+$", "1");
Adjacency vmAdj = new AdjacencyBuilder().setKey(new AdjacencyKey(ipPrefix)).setIpAddress(ipPrefix).setMacAddress(macAddress).setAdjacencyType(Adjacency.AdjacencyType.PrimaryAdjacency).setSubnetId(new Uuid(subnetId.toString())).setSubnetGatewayIp(gatewayIP).build();
if (!adjList.contains(vmAdj)) {
adjList.add(vmAdj);
}
// }
return new AdjacenciesBuilder().setAdjacency(adjList).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.AdjacenciesBuilder 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();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.AdjacenciesBuilder in project netvirt by opendaylight.
the class AbstractSnatService method removeMipAdjacencies.
private void removeMipAdjacencies(Routers routers) {
LOG.info("removeMipAdjacencies for router {}", routers.getRouterName());
String externalSubNetId = null;
for (ExternalIps externalIp : routers.nonnullExternalIps().values()) {
if (!NWUtil.isIpv4Address(externalIp.getIpAddress())) {
// In this class we handle only IPv4 use-cases.
continue;
}
externalSubNetId = externalIp.getSubnetId().getValue();
break;
}
if (externalSubNetId == null) {
LOG.info("removeMipAdjacencies no external Ipv4 address present on router {}", routers.getRouterName());
return;
}
InstanceIdentifier<VpnInterfaces> vpnInterfacesId = InstanceIdentifier.builder(VpnInterfaces.class).build();
try {
VpnInterfaces vpnInterfaces = SingleTransactionDataBroker.syncRead(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnInterfacesId);
List<VpnInterface> updatedVpnInterface = new ArrayList<>();
for (VpnInterface vpnInterface : vpnInterfaces.nonnullVpnInterface().values()) {
List<Adjacency> updatedAdjacencies = new ArrayList<>();
Adjacencies adjacencies = vpnInterface.augmentation(Adjacencies.class);
if (null != adjacencies) {
for (Adjacency adjacency : adjacencies.nonnullAdjacency().values()) {
if (!adjacency.getSubnetId().getValue().equals(externalSubNetId)) {
updatedAdjacencies.add(adjacency);
}
}
}
AdjacenciesBuilder adjacenciesBuilder = new AdjacenciesBuilder();
adjacenciesBuilder.setAdjacency(updatedAdjacencies);
VpnInterfaceBuilder vpnInterfaceBuilder = new VpnInterfaceBuilder(vpnInterface);
vpnInterfaceBuilder.addAugmentation(adjacenciesBuilder.build());
updatedVpnInterface.add(vpnInterfaceBuilder.build());
}
VpnInterfacesBuilder vpnInterfacesBuilder = new VpnInterfacesBuilder();
vpnInterfacesBuilder.setVpnInterface(updatedVpnInterface);
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnInterfacesId, vpnInterfacesBuilder.build());
} catch (ExpectedDataObjectNotFoundException e) {
LOG.warn("Failed to read removeMipAdjacencies with error {}", e.getMessage());
} catch (TransactionCommitFailedException e) {
LOG.warn("Failed to remove removeMipAdjacencies with error {}", e.getMessage());
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.AdjacenciesBuilder in project netvirt by opendaylight.
the class NeutronvpnManager method createPortIpAdjacencies.
protected Adjacencies createPortIpAdjacencies(Port port, Boolean isRouterInterface, TypedWriteTransaction<Configuration> wrtConfigTxn, @Nullable VpnInterface vpnIface) {
List<Adjacency> adjList = new ArrayList<>();
if (vpnIface != null) {
adjList = new ArrayList<>(vpnIface.augmentation(Adjacencies.class).getAdjacency().values());
}
String infName = port.getUuid().getValue();
LOG.trace("neutronVpnManager: create config adjacencies for Port: {}", infName);
for (FixedIps ip : port.nonnullFixedIps().values()) {
String ipValue = ip.getIpAddress().stringValue();
String ipPrefix = ip.getIpAddress().getIpv4Address() != null ? ipValue + "/32" : ipValue + "/128";
Subnetmap snTemp = neutronvpnUtils.getSubnetmap(ip.getSubnetId());
if (snTemp != null && !FibHelper.doesPrefixBelongToSubnet(ipPrefix, snTemp.getSubnetIp(), false)) {
continue;
}
Uuid vpnId = snTemp != null ? snTemp.getVpnId() : null;
if (vpnId != null) {
neutronvpnUtils.createVpnPortFixedIpToPort(vpnId.getValue(), ipValue, infName, port.getMacAddress().getValue(), isRouterInterface, wrtConfigTxn);
// Create Neutron port adjacency if VPN presence is existing for subnet
Adjacency vmAdj = new AdjacencyBuilder().withKey(new AdjacencyKey(ipPrefix)).setIpAddress(ipPrefix).setMacAddress(port.getMacAddress().getValue()).setAdjacencyType(AdjacencyType.PrimaryAdjacency).setSubnetId(ip.getSubnetId()).build();
if (!adjList.contains(vmAdj)) {
adjList.add(vmAdj);
}
}
Uuid routerId = snTemp != null ? snTemp.getRouterId() : null;
if (snTemp != null && snTemp.getInternetVpnId() != null) {
neutronvpnUtils.createVpnPortFixedIpToPort(snTemp.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 = new ArrayList<>(rtr.getRoutes().values());
// 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(getAdjacencyMap(adjList)).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.AdjacenciesBuilder in project netvirt by opendaylight.
the class NeutronvpnManager method withdrawPortIpFromVpnIface.
protected void withdrawPortIpFromVpnIface(Uuid vpnId, Uuid internetVpnId, Port port, Subnetmap sn, WriteTransaction wrtConfigTxn) {
String infName = port.getUuid().getValue();
InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
Optional<VpnInterface> optionalVpnInterface = null;
LOG.debug("withdrawPortIpFromVpnIface vpn {} internetVpn {} Port {}", vpnId, internetVpnId, infName);
try {
optionalVpnInterface = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
} catch (ReadFailedException e) {
LOG.error("withdrawPortIpFromVpnIface: Error reading the VPN interface for {}", vpnIfIdentifier, e);
return;
}
if (!optionalVpnInterface.isPresent()) {
return;
}
LOG.trace("withdraw adjacencies for Port: {} subnet {}", port.getUuid().getValue(), sn != null ? sn.getSubnetIp() : "null");
List<Adjacency> vpnAdjsList = optionalVpnInterface.get().getAugmentation(Adjacencies.class).getAdjacency();
List<Adjacency> updatedAdjsList = new ArrayList<>();
boolean isIpFromAnotherSubnet = false;
for (Adjacency adj : vpnAdjsList) {
String adjString = FibHelper.getIpFromPrefix(adj.getIpAddress());
if (sn == null || !Objects.equals(adj.getSubnetId(), sn.getId())) {
if (adj.getAdjacencyType() == AdjacencyType.PrimaryAdjacency) {
isIpFromAnotherSubnet = true;
}
updatedAdjsList.add(adj);
continue;
}
if (adj.getAdjacencyType() == AdjacencyType.PrimaryAdjacency) {
LOG.error("withdrawPortIpFromVpnIface: suppressing primaryAdjacency {} FixedIp for vpnId {}", adjString, vpnId);
if (vpnId != null) {
neutronvpnUtils.removeVpnPortFixedIpToPort(vpnId.getValue(), String.valueOf(adjString), wrtConfigTxn);
}
if (internetVpnId != null) {
neutronvpnUtils.removeVpnPortFixedIpToPort(internetVpnId.getValue(), String.valueOf(adjString), wrtConfigTxn);
}
} else {
if (port.getDeviceOwner().equals(NeutronConstants.DEVICE_OWNER_ROUTER_INF) && sn.getRouterId() != null) {
Router rtr = neutronvpnUtils.getNeutronRouter(sn.getRouterId());
if (rtr != null && rtr.getRoutes() != null) {
List<Routes> extraRoutesToRemove = new ArrayList<>();
for (Routes rt : rtr.getRoutes()) {
if (rt.getNexthop().toString().equals(adjString)) {
extraRoutesToRemove.add(rt);
}
}
if (vpnId != null) {
LOG.error("withdrawPortIpFromVpnIface: suppressing extraRoute {} for vpnId {}", extraRoutesToRemove, vpnId);
removeAdjacencyforExtraRoute(vpnId, extraRoutesToRemove);
}
/* removeAdjacencyforExtraRoute done also for internet-vpn-id, in previous call */
}
}
}
}
Adjacencies adjacencies = new AdjacenciesBuilder().setAdjacency(updatedAdjsList).build();
if (vpnId != null) {
updateVpnInterfaceWithAdjacencies(vpnId, infName, adjacencies, wrtConfigTxn);
}
if (internetVpnId != null) {
updateVpnInterfaceWithAdjacencies(internetVpnId, infName, adjacencies, wrtConfigTxn);
}
if (!isIpFromAnotherSubnet) {
// no more subnetworks for neutron port
if (sn != null && sn.getRouterId() != null) {
removeFromNeutronRouterInterfacesMap(sn.getRouterId(), port.getUuid().getValue());
}
deleteVpnInterface(infName, null, /* vpn-id */
wrtConfigTxn);
return;
}
return;
}
Aggregations