use of org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.Container in project netvirt by opendaylight.
the class NAPTSwitchSelector method selectNewNAPTSwitch.
Uint64 selectNewNAPTSwitch(String routerName, List<Uint64> excludeDpns) {
LOG.info("selectNewNAPTSwitch : Select a new NAPT switch for router {}", routerName);
Map<Uint64, Integer> naptSwitchWeights = constructNAPTSwitches();
List<Uint64> routerSwitches = getDpnsForVpn(routerName);
if (routerSwitches.isEmpty()) {
LOG.warn("selectNewNAPTSwitch : Delaying NAPT switch selection due to no dpns scenario for router {}", routerName);
return Uint64.ZERO;
}
try {
if (excludeDpns != null) {
routerSwitches.removeAll(excludeDpns);
}
LOG.debug("selectNewNAPTSwitch : routerSwitches before filtering : {}", routerSwitches);
routerSwitches = tombstonedNodeManager.filterTombStoned(routerSwitches);
LOG.debug("selectNewNAPTSwitch : routerSwitches after filtering : {}", routerSwitches);
} catch (ReadFailedException ex) {
LOG.error("selectNewNAPTSwitch : filterTombStoned Exception thrown", ex);
}
Set<SwitchWeight> switchWeights = new TreeSet<>();
for (Uint64 dpn : routerSwitches) {
if (naptSwitchWeights.get(dpn) != null) {
switchWeights.add(new SwitchWeight(dpn, naptSwitchWeights.get(dpn)));
} else {
switchWeights.add(new SwitchWeight(dpn, 0));
}
}
Uint64 primarySwitch;
if (!switchWeights.isEmpty()) {
LOG.debug("selectNewNAPTSwitch : Current switch weights for router {} - {}", routerName, switchWeights);
RouterToNaptSwitchBuilder routerToNaptSwitchBuilder = new RouterToNaptSwitchBuilder().setRouterName(routerName);
SwitchWeight firstSwitchWeight = switchWeights.iterator().next();
primarySwitch = firstSwitchWeight.getSwitch();
RouterToNaptSwitch id = routerToNaptSwitchBuilder.setPrimarySwitchId(primarySwitch).build();
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, getNaptSwitchesIdentifier(routerName), id);
LOG.debug("selectNewNAPTSwitch : successful addition of RouterToNaptSwitch to napt-switches container");
return primarySwitch;
} else {
primarySwitch = Uint64.ZERO;
LOG.debug("selectNewNAPTSwitch : switchWeights empty, primarySwitch: {} ", primarySwitch);
return primarySwitch;
}
}
use of org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.Container in project netvirt by opendaylight.
the class ExternalNetworksChangeListener method remove.
@Override
public void remove(InstanceIdentifier<Networks> identifier, Networks networks) {
if (identifier == null || networks == null || networks.getRouterIds() == null || networks.getRouterIds().isEmpty()) {
LOG.warn("remove : returning without processing since networks/identifier is null: " + "identifier: {}, networks: {}", identifier, networks);
return;
}
for (Uuid routerId : networks.getRouterIds()) {
String routerName = routerId.toString();
InstanceIdentifier<RouterToNaptSwitch> routerToNaptSwitchInstanceIdentifier = NatUtil.buildNaptSwitchIdentifier(routerName);
MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.OPERATIONAL, routerToNaptSwitchInstanceIdentifier);
LOG.debug("remove : successful deletion of data in napt-switches container");
}
}
use of org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.Container in project netvirt by opendaylight.
the class ExternalRoutersListener method changeLocalVpnIdToBgpVpnId.
/**
* router association to vpn.
*
* @param routerName - Name of router
* @param routerId - router id
* @param bgpVpnName BGP VPN name
*/
public void changeLocalVpnIdToBgpVpnId(String routerName, Uint32 routerId, String extNetwork, String bgpVpnName, TypedWriteTransaction<Configuration> writeFlowInvTx, ProviderTypes extNwProvType) {
LOG.debug("changeLocalVpnIdToBgpVpnId : Router associated to BGP VPN");
if (chkExtRtrAndSnatEnbl(new Uuid(routerName))) {
Uint32 bgpVpnId = NatUtil.getVpnId(dataBroker, bgpVpnName);
LOG.debug("changeLocalVpnIdToBgpVpnId : BGP VPN ID value {} ", bgpVpnId);
if (bgpVpnId != NatConstants.INVALID_ID) {
LOG.debug("changeLocalVpnIdToBgpVpnId : Populate the router-id-name container with the " + "mapping BGP VPN-ID {} -> BGP VPN-NAME {}", bgpVpnId, bgpVpnName);
RouterIds rtrs = new RouterIdsBuilder().withKey(new RouterIdsKey(bgpVpnId)).setRouterId(bgpVpnId).setRouterName(bgpVpnName).build();
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, getRoutersIdentifier(bgpVpnId), rtrs);
// Get the allocated Primary NAPT Switch for this router
LOG.debug("changeLocalVpnIdToBgpVpnId : Update the Router ID {} to the BGP VPN ID {} ", routerId, bgpVpnId);
addDefaultFibRouteForSnatWithBgpVpn(routerName, routerId, bgpVpnId, writeFlowInvTx);
// Get the group ID
Uint64 primarySwitchId = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
installFlowsWithUpdatedVpnId(primarySwitchId, routerName, bgpVpnId, routerId, new Uuid(extNetwork), true, writeFlowInvTx, extNwProvType);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.Container in project netvirt by opendaylight.
the class ExternalRoutersListener method add.
@Override
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void add(InstanceIdentifier<Routers> identifier, Routers routers) {
if (natMode != NatMode.Controller) {
return;
}
// Populate the router-id-name container
String routerName = routers.getRouterName();
LOG.info("add : external router event for {}", routerName);
Uint32 routerId = NatUtil.getVpnId(dataBroker, routerName);
NatUtil.createRouterIdsConfigDS(dataBroker, routerId, routerName);
Uuid bgpVpnUuid = NatUtil.getVpnForRouter(dataBroker, routerName);
try {
if (routers.isEnableSnat()) {
coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + routers.key(), () -> Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, confTx -> {
LOG.info("add : Installing NAT default route on all dpns part of router {}", routerName);
Uint32 bgpVpnId = NatConstants.INVALID_ID;
if (bgpVpnUuid != null) {
bgpVpnId = NatUtil.getVpnId(dataBroker, bgpVpnUuid.getValue());
}
addOrDelDefFibRouteToSNAT(routerName, routerId, bgpVpnId, bgpVpnUuid, true, confTx);
// Allocate Primary Napt Switch for this router
Uint64 primarySwitchId = getPrimaryNaptSwitch(routerName);
if (primarySwitchId != null && !primarySwitchId.equals(Uint64.ZERO)) {
handleEnableSnat(routers, routerId, primarySwitchId, bgpVpnId, confTx);
}
})), NatConstants.NAT_DJC_MAX_RETRIES);
} else {
LOG.info("add : SNAT is disabled for external router {} ", routerName);
}
} catch (Exception ex) {
LOG.error("add : Exception while Installing NAT flows on all dpns as part of router {}", routerName, ex);
}
}
use of org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.Container in project netvirt by opendaylight.
the class SubnetOpDpnManager method addInterfaceToDpn.
public SubnetToDpn addInterfaceToDpn(Uuid subnetId, Uint64 dpnId, String intfName) {
SubnetToDpn subDpn = null;
try {
// Create and add SubnetOpDataEntry object for this subnet to the SubnetOpData container
InstanceIdentifier<SubnetOpDataEntry> subOpIdentifier = InstanceIdentifier.builder(SubnetOpData.class).child(SubnetOpDataEntry.class, new SubnetOpDataEntryKey(subnetId)).build();
// Please use a synchronize block here as we donot need a cluster-wide lock
InstanceIdentifier<SubnetToDpn> dpnOpId = subOpIdentifier.child(SubnetToDpn.class, new SubnetToDpnKey(dpnId));
Optional<SubnetToDpn> optionalSubDpn = SingleTransactionDataBroker.syncReadOptional(broker, LogicalDatastoreType.OPERATIONAL, dpnOpId);
if (!optionalSubDpn.isPresent()) {
// Create a new DPN Entry
subDpn = addDpnToSubnet(subnetId, dpnId);
} else {
subDpn = optionalSubDpn.get();
}
SubnetToDpnBuilder subDpnBuilder = new SubnetToDpnBuilder(subDpn);
Map<VpnInterfacesKey, VpnInterfaces> vpnInterfaceMap = new HashMap<>();
vpnInterfaceMap = subDpnBuilder.getVpnInterfaces() != null ? new HashMap<>(subDpnBuilder.getVpnInterfaces()) : vpnInterfaceMap;
VpnInterfaces vpnIntfs = new VpnInterfacesBuilder().withKey(new VpnInterfacesKey(intfName)).setInterfaceName(intfName).build();
vpnInterfaceMap.put(vpnIntfs.key(), vpnIntfs);
subDpnBuilder.setVpnInterfaces(vpnInterfaceMap);
subDpn = subDpnBuilder.build();
SingleTransactionDataBroker.syncWrite(broker, LogicalDatastoreType.OPERATIONAL, dpnOpId, subDpn, VpnUtil.SINGLE_TRANSACTION_BROKER_NO_RETRY);
LOG.info("addInterfaceToDpn: Created SubnetToDpn entry for subnet {} with DPNId {} intfName {}", subnetId.getValue(), dpnId, intfName);
} catch (TransactionCommitFailedException ex) {
LOG.error("addInterfaceToDpn: Addition of Interface {} for SubnetToDpn on subnet {} with DPN {} failed", intfName, subnetId.getValue(), dpnId, ex);
} catch (InterruptedException | ExecutionException e) {
LOG.error("addInterfaceToDpn: Failed to read data store for interface {} subnet {} dpn {}", intfName, subnetId, dpnId);
}
return subDpn;
}
Aggregations