use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.routers.Router in project netvirt by opendaylight.
the class NatVpnMapsChangeListener method onRouterAssociatedToVpn.
public void onRouterAssociatedToVpn(String vpnName, String routerName) {
// check router is associated to external network
String extNetwork = NatUtil.getAssociatedExternalNetwork(dataBroker, routerName);
if (extNetwork != null) {
try {
LOG.debug("onRouterAssociatedToVpn : Router {} is associated with ext nw {}", routerName, extNetwork);
handleDNATConfigurationForRouterAssociation(routerName, vpnName, extNetwork);
Uuid extNetworkUuid = NatUtil.getNetworkIdFromRouterName(dataBroker, routerName);
if (extNetworkUuid == null) {
LOG.error("onRouterAssociatedToVpn : Unable to retrieve external network Uuid for router {}", routerName);
return;
}
ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName, extNetworkUuid);
if (extNwProvType == null) {
LOG.error("onRouterAssociatedToVpn : External Network Provider Type missing");
return;
}
Uint32 routerId = NatUtil.getVpnId(dataBroker, routerName);
txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> externalRoutersListener.changeLocalVpnIdToBgpVpnId(routerName, routerId, extNetwork, vpnName, tx, extNwProvType)).get();
} catch (InterruptedException | ExecutionException e) {
LOG.error("Error changling local VPN identifier to BGP VPN identifier", e);
}
} else {
LOG.debug("onRouterAssociatedToVpn : Ignoring the Router {} association with VPN {} " + "since it is not external router", routerName, vpnName);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.routers.Router in project netvirt by opendaylight.
the class NatVpnMapsChangeListener method remove.
@Override
public void remove(InstanceIdentifier<VpnMap> identifier, VpnMap vpnMap) {
Uuid vpnUuid = vpnMap.getVpnId();
String vpnName = vpnUuid.getValue();
if (vpnMap.getRouterIds() != null) {
vpnMap.nonnullRouterIds().values().stream().filter(router -> !(Objects.equals(router.getRouterId(), vpnUuid))).forEach(router -> {
String routerName = router.getRouterId().getValue();
LOG.info("REMOVE: Router {} is disassociated from Vpn {}", routerName, vpnName);
onRouterDisassociatedFromVpn(vpnName, routerName);
});
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.routers.Router in project netvirt by opendaylight.
the class NatVpnMapsChangeListener method handleDNATConfigurationForRouterAssociation.
void handleDNATConfigurationForRouterAssociation(String routerName, String vpnName, String externalNetwork) throws ExecutionException, InterruptedException {
InstanceIdentifier<RouterPorts> routerPortsId = NatUtil.getRouterPortsId(routerName);
Optional<RouterPorts> optRouterPorts = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsId);
if (!optRouterPorts.isPresent()) {
LOG.debug("handleDNATConfigurationForRouterAssociation : Could not read Router Ports data " + "object with id: {} to handle associate vpn {}", routerName, vpnName);
return;
}
Uuid networkId = Uuid.getDefaultInstance(externalNetwork);
for (Ports port : optRouterPorts.get().nonnullPorts().values()) {
String portName = port.getPortName();
Uint64 dpnId = NatUtil.getDpnForInterface(interfaceManager, portName);
if (dpnId.equals(Uint64.ZERO)) {
LOG.warn("handleDNATConfigurationForRouterAssociation : DPN not found for {}, " + "skip handling of router {} association with vpn {}", portName, routerName, vpnName);
continue;
}
for (InternalToExternalPortMap intExtPortMap : port.nonnullInternalToExternalPortMap().values()) {
// remove all NAT related entries with routerName
// floatingIpListener.removeNATOnlyFlowEntries(dpnId, portName, routerName, null,
// intExtPortMap.getInternalIp(), externalIp);
// Create NAT entries with VPN Id
LOG.debug("handleDNATConfigurationForRouterAssociation : Updating DNAT flows with VPN metadata {} ", vpnName);
floatingIpListener.createNATOnlyFlowEntries(dpnId, routerName, vpnName, networkId, intExtPortMap);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.routers.Router in project netvirt by opendaylight.
the class NatVpnMapsChangeListener method update.
@Override
public void update(InstanceIdentifier<VpnMap> identifier, VpnMap original, VpnMap updated) {
Uuid vpnUuid = updated.getVpnId();
String vpnName = vpnUuid.getValue();
List<RouterIds> updatedRouterIdList = new ArrayList<RouterIds>(updated.nonnullRouterIds().values());
List<RouterIds> originalRouterIdList = new ArrayList<RouterIds>(original.nonnullRouterIds().values());
List<RouterIds> routersAddedList = null;
List<RouterIds> routersRemovedList = null;
if (originalRouterIdList == null && updatedRouterIdList != null) {
routersAddedList = updatedRouterIdList;
} else if (originalRouterIdList != null && updatedRouterIdList != null) {
routersAddedList = updatedRouterIdList.stream().filter(routerId -> (!originalRouterIdList.contains(routerId))).collect(Collectors.toList());
}
if (originalRouterIdList != null && updatedRouterIdList == null) {
routersRemovedList = originalRouterIdList;
} else if (originalRouterIdList != null && updatedRouterIdList != null) {
routersRemovedList = originalRouterIdList.stream().filter(routerId -> (!updatedRouterIdList.contains(routerId))).collect(Collectors.toList());
}
if (routersAddedList != null) {
routersAddedList.stream().filter(router -> !(Objects.equals(router.getRouterId(), updated.getVpnId()))).forEach(router -> {
String routerName = router.getRouterId().getValue();
onRouterAssociatedToVpn(vpnName, routerName);
});
}
if (routersRemovedList != null) {
routersRemovedList.stream().filter(router -> !(Objects.equals(router.getRouterId(), original.getVpnId()))).forEach(router -> {
String routerName = router.getRouterId().getValue();
onRouterDisassociatedFromVpn(vpnName, routerName);
});
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.routers.Router in project netvirt by opendaylight.
the class RouterPortsListener method add.
@Override
public void add(final InstanceIdentifier<RouterPorts> identifier, final RouterPorts routerPorts) {
LOG.trace("add : key:{} value:{}", routerPorts.key(), routerPorts);
Optional<RouterPorts> optRouterPorts = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, identifier);
if (optRouterPorts.isPresent()) {
RouterPorts ports = optRouterPorts.get();
String routerName = ports.getRouterId();
MDSALUtil.syncUpdate(dataBroker, LogicalDatastoreType.OPERATIONAL, identifier, new RouterPortsBuilder().withKey(new RouterPortsKey(routerName)).setRouterId(routerName).setExternalNetworkId(routerPorts.getExternalNetworkId()).build());
} else {
String routerName = routerPorts.getRouterId();
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, identifier, new RouterPortsBuilder().withKey(new RouterPortsKey(routerName)).setRouterId(routerName).setExternalNetworkId(routerPorts.getExternalNetworkId()).build());
}
// Check if the router is associated with any BGP VPN and update the association
String routerName = routerPorts.getRouterId();
Uuid vpnName = NatUtil.getVpnForRouter(dataBroker, routerName);
if (vpnName != null) {
InstanceIdentifier<Routermapping> routerMappingId = NatUtil.getRouterVpnMappingId(routerName);
Optional<Routermapping> optRouterMapping = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, routerMappingId);
if (!optRouterMapping.isPresent()) {
Uint32 vpnId = NatUtil.getVpnId(dataBroker, vpnName.getValue());
LOG.debug("add : Updating router {} to VPN {} association with Id {}", routerName, vpnName, vpnId);
Routermapping routerMapping = new RoutermappingBuilder().withKey(new RoutermappingKey(routerName)).setRouterName(routerName).setVpnName(vpnName.getValue()).setVpnId(vpnId).build();
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, routerMappingId, routerMapping);
}
}
}
Aggregations