use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap 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;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap in project netvirt by opendaylight.
the class NeutronvpnManager method updateSubnetNode.
protected Subnetmap updateSubnetNode(Uuid subnetId, Uuid routerId, Uuid vpnId, Uuid internetvpnId) {
Subnetmap subnetmap = null;
SubnetmapBuilder builder = null;
InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class, new SubnetmapKey(subnetId)).build();
try {
synchronized (subnetId.getValue().intern()) {
Optional<Subnetmap> sn = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
if (sn.isPresent()) {
builder = new SubnetmapBuilder(sn.get());
LOG.debug("updating existing subnetmap node for subnet ID {}", subnetId.getValue());
} else {
LOG.error("subnetmap node for subnet {} does not exist, returning", subnetId.getValue());
return null;
}
if (routerId != null) {
builder.setRouterId(routerId);
}
if (vpnId != null) {
builder.setVpnId(vpnId);
}
builder.setInternetVpnId(internetvpnId);
subnetmap = builder.build();
LOG.debug("Creating/Updating subnetMap node: {} ", subnetId.getValue());
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id, subnetmap);
}
} catch (ReadFailedException | TransactionCommitFailedException e) {
LOG.error("Subnet map update failed for node {}", subnetId.getValue(), e);
}
return subnetmap;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap in project netvirt by opendaylight.
the class NeutronvpnManager method removePortsFromSubnetmapNode.
protected Subnetmap removePortsFromSubnetmapNode(Uuid subnetId, Uuid portId, Uuid directPortId) {
Subnetmap subnetmap = null;
InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class, new SubnetmapKey(subnetId)).build();
try {
synchronized (subnetId.getValue().intern()) {
Optional<Subnetmap> sn = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
if (sn.isPresent()) {
SubnetmapBuilder builder = new SubnetmapBuilder(sn.get());
if (null != portId && null != builder.getPortList()) {
List<Uuid> portList = builder.getPortList();
portList.remove(portId);
builder.setPortList(portList);
LOG.debug("Removing port {} from existing subnetmap node: {} ", portId.getValue(), subnetId.getValue());
}
if (null != directPortId && null != builder.getDirectPortList()) {
List<Uuid> directPortList = builder.getDirectPortList();
directPortList.remove(directPortId);
builder.setDirectPortList(directPortList);
LOG.debug("Removing direct port {} from existing subnetmap node: {} ", directPortId.getValue(), subnetId.getValue());
}
subnetmap = builder.build();
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id, subnetmap);
} else {
LOG.info("Trying to remove port from non-existing subnetmap node {}", subnetId.getValue());
}
}
} catch (ReadFailedException | TransactionCommitFailedException e) {
LOG.error("Removing a port from port list of a subnetmap failed for node: {}", subnetId.getValue(), e);
}
return subnetmap;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap in project netvirt by opendaylight.
the class NeutronvpnManager method dissociateRouterFromVpn.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
protected void dissociateRouterFromVpn(Uuid vpnId, Uuid routerId) {
List<Uuid> routerSubnets = neutronvpnUtils.getNeutronRouterSubnetIds(routerId);
boolean vpnInstanceIpVersionsRemoved = false;
IpVersionChoice vpnInstanceIpVersionsToRemove = IpVersionChoice.UNDEFINED;
for (Uuid subnetId : routerSubnets) {
Subnetmap sn = neutronvpnUtils.getSubnetmap(subnetId);
if (neutronvpnUtils.shouldVpnHandleIpVersionChangeToRemove(sn, vpnId)) {
vpnInstanceIpVersionsToRemove = vpnInstanceIpVersionsToRemove.addVersion(NeutronvpnUtils.getIpVersionFromString(sn.getSubnetIp()));
vpnInstanceIpVersionsRemoved = true;
}
LOG.debug("Updating association of subnets to internal vpn {}", routerId.getValue());
updateVpnForSubnet(vpnId, routerId, subnetId, false);
}
if (vpnInstanceIpVersionsRemoved) {
neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), vpnInstanceIpVersionsToRemove, false);
}
clearFromVpnMaps(vpnId, routerId, null);
try {
checkAndPublishRouterDisassociatedFromVpnNotification(routerId, vpnId);
LOG.debug("notification upon disassociation of router {} from VPN {} published", routerId.getValue(), vpnId.getValue());
} catch (Exception e) {
LOG.error("publishing of notification upon disassociation of router {} from VPN {} failed : ", routerId.getValue(), vpnId.getValue(), e);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap in project netvirt by opendaylight.
the class NeutronvpnManager method updateVpnInternetForSubnet.
protected void updateVpnInternetForSubnet(Subnetmap sm, Uuid vpn, boolean isBeingAssociated) {
LOG.debug("updateVpnInternetForSubnet: {} subnet {} with BGPVPN Internet {} ", isBeingAssociated ? "associating" : "dissociating", sm.getSubnetIp(), vpn.getValue());
Uuid internalVpnId = sm.getVpnId();
if (internalVpnId == null) {
LOG.error("updateVpnInternetForSubnet: can not find Internal or BGPVPN Id for subnet {}, bailing out", sm.getId().getValue());
return;
}
if (isBeingAssociated) {
updateSubnetNode(sm.getId(), null, sm.getVpnId(), vpn);
} else {
updateSubnetNode(sm.getId(), null, sm.getVpnId(), null);
}
jobCoordinator.enqueueJob("VPN-" + vpn.getValue(), () -> singletonList(managedNewTransactionRunner.callWithNewWriteOnlyTransactionAndSubmit(wrtConfigTxn -> {
if (isBeingAssociated) {
updateVpnInterface(vpn, null, neutronvpnUtils.getNeutronPort(sm.getRouterInterfacePortId()), true, true, wrtConfigTxn);
} else {
removeVpnFromVpnInterface(vpn, neutronvpnUtils.getNeutronPort(sm.getRouterInterfacePortId()), wrtConfigTxn, sm);
}
})));
// Check for ports on this subnet and update association of
// corresponding vpn-interfaces to internet vpn
List<Uuid> portList = sm.getPortList();
if (portList != null) {
for (Uuid port : portList) {
LOG.debug("Updating vpn-interface for port {} isBeingAssociated {}", port.getValue(), isBeingAssociated);
jobCoordinator.enqueueJob("PORT-" + port.getValue(), () -> {
WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
List<ListenableFuture<Void>> futures = new ArrayList<>();
if (isBeingAssociated) {
updateVpnInterface(vpn, null, neutronvpnUtils.getNeutronPort(port), isBeingAssociated, false, wrtConfigTxn);
} else {
removeVpnFromVpnInterface(vpn, neutronvpnUtils.getNeutronPort(port), wrtConfigTxn, sm);
}
futures.add(wrtConfigTxn.submit());
return futures;
});
}
}
}
Aggregations