use of org.opendaylight.yangtools.yang.common.Uint32 in project netvirt by opendaylight.
the class NatUtil method buildDefaultNATFlowEntityForExternalSubnet.
@Nullable
static FlowEntity buildDefaultNATFlowEntityForExternalSubnet(Uint64 dpId, Uint32 vpnId, String subnetId, IdManagerService idManager) {
InetAddress defaultIP = null;
try {
defaultIP = InetAddress.getByName("0.0.0.0");
} catch (UnknownHostException e) {
LOG.error("buildDefaultNATFlowEntityForExternalSubnet : Failed to build FIB Table Flow for " + "Default Route to NAT.", e);
return null;
}
List<MatchInfo> matches = new ArrayList<>();
matches.add(MatchEthernetType.IPV4);
// add match for vrfid
matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(vpnId.longValue()), MetaDataUtil.METADATA_MASK_VRFID));
List<InstructionInfo> instructions = new ArrayList<>();
List<ActionInfo> actionsInfo = new ArrayList<>();
Uint32 groupId = getUniqueId(idManager, NatConstants.SNAT_IDPOOL_NAME, NatUtil.getGroupIdKey(subnetId));
if (groupId == NatConstants.INVALID_ID) {
LOG.error("Unable to get groupId for subnet {} while building defauly flow entity", subnetId);
return null;
}
actionsInfo.add(new ActionGroup(groupId.longValue()));
String flowRef = getFlowRef(dpId, NwConstants.L3_FIB_TABLE, defaultIP, vpnId);
instructions.add(new InstructionApplyActions(actionsInfo));
return MDSALUtil.buildFlowEntity(dpId, NwConstants.L3_FIB_TABLE, flowRef, NatConstants.DEFAULT_DNAT_FLOW_PRIORITY, flowRef, 0, 0, NwConstants.COOKIE_DNAT_TABLE, matches, instructions);
}
use of org.opendaylight.yangtools.yang.common.Uint32 in project netvirt by opendaylight.
the class NatUtil method handleSNATForDPN.
@SuppressWarnings("checkstyle:IllegalCatch")
public static void handleSNATForDPN(DataBroker dataBroker, IMdsalApiManager mdsalManager, IdManagerService idManager, NaptSwitchHA naptSwitchHA, Uint64 dpnId, Routers extRouters, Uint32 routerId, Uint32 routerVpnId, TypedReadWriteTransaction<Configuration> confTx, ProviderTypes extNwProvType, UpgradeState upgradeState) {
// Check if primary and secondary switch are selected, If not select the role
// Install select group to NAPT switch
// Install default miss entry to NAPT switch
Uint64 naptSwitch;
String routerName = extRouters.getRouterName();
Boolean upgradeInProgress = false;
if (upgradeState != null) {
upgradeInProgress = upgradeState.isUpgradeInProgress();
}
Uint64 naptId = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
if (naptId == null || naptId.equals(Uint64.ZERO) || !NatUtil.getSwitchStatus(dataBroker, naptId) && upgradeInProgress == false) {
LOG.debug("handleSNATForDPN : NaptSwitch is down or not selected for router {},naptId {}", routerName, naptId);
naptSwitch = dpnId;
boolean naptstatus = naptSwitchHA.updateNaptSwitch(routerName, naptSwitch);
if (!naptstatus) {
LOG.error("handleSNATForDPN : Failed to update newNaptSwitch {} for routername {}", naptSwitch, routerName);
return;
}
LOG.debug("handleSNATForDPN : Switch {} is elected as NaptSwitch for router {}", dpnId, routerName);
String externalVpnName = null;
NatUtil.createRouterIdsConfigDS(dataBroker, routerId, routerName);
naptSwitchHA.subnetRegisterMapping(extRouters, routerId);
Uuid extNwUuid = extRouters.getNetworkId();
externalVpnName = NatUtil.getAssociatedVPN(dataBroker, extNwUuid);
if (externalVpnName != null) {
naptSwitchHA.installSnatFlows(routerName, routerId, naptSwitch, routerVpnId, extNwUuid, externalVpnName, confTx);
}
// Install miss entry (table 26) pointing to table 46
FlowEntity flowEntity = naptSwitchHA.buildSnatFlowEntityForNaptSwitch(dpnId, routerName, routerVpnId, NatConstants.ADD_FLOW);
if (flowEntity == null) {
LOG.error("handleSNATForDPN : Failed to populate flowentity for router {} with dpnId {}", routerName, dpnId);
return;
}
LOG.debug("handleSNATForDPN : Successfully installed flow for dpnId {} router {}", dpnId, routerName);
mdsalManager.addFlow(confTx, flowEntity);
// Removing primary flows from old napt switch
if (naptId != null && !naptId.equals(Uint64.ZERO)) {
LOG.debug("handleSNATForDPN : Removing primary flows from old napt switch {} for router {}", naptId, routerName);
try {
naptSwitchHA.removeSnatFlowsInOldNaptSwitch(extRouters, routerId, naptId, null, externalVpnName, confTx);
} catch (Exception e) {
LOG.error("Exception while removing SnatFlows form OldNaptSwitch {}", naptId, e);
}
}
naptSwitchHA.updateNaptSwitchBucketStatus(routerName, routerId, naptSwitch);
} else if (naptId.equals(dpnId)) {
LOG.error("handleSNATForDPN : NaptSwitch {} gone down during cluster reboot came alive", naptId);
} else {
naptSwitch = naptId;
LOG.debug("handleSNATForDPN : Napt switch with Id {} is already elected for router {}", naptId, routerName);
// installing group
List<BucketInfo> bucketInfo = naptSwitchHA.handleGroupInNeighborSwitches(dpnId, routerName, routerId, naptSwitch);
naptSwitchHA.installSnatGroupEntry(dpnId, bucketInfo, routerName);
// Install miss entry (table 26) pointing to group
Uint32 groupId = NatUtil.getUniqueId(idManager, NatConstants.SNAT_IDPOOL_NAME, NatUtil.getGroupIdKey(routerName));
if (groupId != NatConstants.INVALID_ID) {
FlowEntity flowEntity = naptSwitchHA.buildSnatFlowEntity(dpnId, routerName, groupId.longValue(), routerVpnId, NatConstants.ADD_FLOW);
if (flowEntity == null) {
LOG.error("handleSNATForDPN : Failed to populate flowentity for router {} with dpnId {}" + " groupId {}", routerName, dpnId, groupId);
return;
}
LOG.debug("handleSNATForDPN : Successfully installed flow for dpnId {} router {} group {}", dpnId, routerName, groupId);
mdsalManager.addFlow(confTx, flowEntity);
} else {
LOG.error("handleSNATForDPN: Unable to get groupId for router:{}", routerName);
}
}
}
use of org.opendaylight.yangtools.yang.common.Uint32 in project netvirt by opendaylight.
the class NatUtil method getExternalVpnIdForExtNetwork.
public static Uint32 getExternalVpnIdForExtNetwork(DataBroker broker, Uuid externalNwUuid) {
// Get the VPN ID from the ExternalNetworks model
if (externalNwUuid == null) {
LOG.error("getExternalVpnIdForExtNetwork : externalNwUuid is null");
return null;
}
Uuid vpnUuid = getVpnIdfromNetworkId(broker, externalNwUuid);
if (vpnUuid == null) {
LOG.error("NAT Service : vpnUuid is null");
return null;
}
Uint32 vpnId = getVpnId(broker, vpnUuid.getValue());
return vpnId;
}
use of org.opendaylight.yangtools.yang.common.Uint32 in project netvirt by opendaylight.
the class NatUtil method getNetworkVpnIdFromRouterId.
public static Uint32 getNetworkVpnIdFromRouterId(DataBroker broker, Uint32 routerId) {
// Get the external network ID from the ExternalRouter model
Uuid networkId = NatUtil.getNetworkIdFromRouterId(broker, routerId);
if (networkId == null) {
LOG.error("getNetworkVpnIdFromRouterId : networkId is null");
return NatConstants.INVALID_ID;
}
// Get the VPN ID from the ExternalNetworks model
Uuid vpnUuid = NatUtil.getVpnIdfromNetworkId(broker, networkId);
if (vpnUuid == null) {
LOG.error("getNetworkVpnIdFromRouterId : vpnUuid is null");
return NatConstants.INVALID_ID;
}
Uint32 vpnId = NatUtil.getVpnId(broker, vpnUuid.getValue());
return vpnId;
}
use of org.opendaylight.yangtools.yang.common.Uint32 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);
}
}
Aggregations