use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnets.associated.to.route.targets.route.target.associated.subnet.AssociatedVpn in project netvirt by opendaylight.
the class FloatingIPListener method addOrDelDefaultFibRouteForDnat.
private void addOrDelDefaultFibRouteForDnat(BigInteger dpnId, String routerName, long routerId, WriteTransaction tx, boolean create) {
Boolean wrTxPresent = true;
if (tx == null) {
wrTxPresent = false;
tx = dataBroker.newWriteOnlyTransaction();
}
// Check if the router to bgp-vpn association is present
long associatedVpnId = NatConstants.INVALID_ID;
Uuid associatedVpn = NatUtil.getVpnForRouter(dataBroker, routerName);
if (associatedVpn != null) {
associatedVpnId = NatUtil.getVpnId(dataBroker, associatedVpn.getValue());
}
if (create) {
if (associatedVpnId != NatConstants.INVALID_ID) {
LOG.debug("addOrDelDefaultFibRouteForDnat: Install NAT default route on DPN {} for the router {} with " + "vpn-id {}", dpnId, routerName, associatedVpnId);
defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, associatedVpnId, routerId, tx);
} else {
LOG.debug("addOrDelDefaultFibRouteForDnat: Install NAT default route on DPN {} for the router {} with " + "vpn-id {}", dpnId, routerName, routerId);
defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, routerId, tx);
}
} else {
if (associatedVpnId != NatConstants.INVALID_ID) {
LOG.debug("addOrDelDefaultFibRouteForDnat: Remove NAT default route on DPN {} for the router {} " + "with vpn-id {}", dpnId, routerName, associatedVpnId);
defaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, associatedVpnId, routerId, tx);
} else {
LOG.debug("addOrDelDefaultFibRouteForDnat: Remove NAT default route on DPN {} for the router {} " + "with vpn-id {}", dpnId, routerName, routerId);
defaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, routerId, tx);
}
}
if (!wrTxPresent) {
tx.submit();
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnets.associated.to.route.targets.route.target.associated.subnet.AssociatedVpn in project netvirt by opendaylight.
the class FloatingIPListener method createNATFlowEntries.
void createNATFlowEntries(String interfaceName, final InternalToExternalPortMap mapping, final InstanceIdentifier<RouterPorts> portIid, final String routerName, WriteTransaction writeFlowInvTx) {
if (!validateIpMapping(mapping)) {
LOG.error("createNATFlowEntries : Not a valid ip addresses in the mapping {}", mapping);
return;
}
// Get the DPN on which this interface resides
BigInteger dpnId = NatUtil.getDpnForInterface(interfaceManager, interfaceName);
if (dpnId.equals(BigInteger.ZERO)) {
LOG.warn("createNATFlowEntries : No DPN for interface {}. NAT flow entries for ip mapping {} will " + "not be installed", interfaceName, mapping);
return;
}
long routerId = NatUtil.getVpnId(dataBroker, routerName);
if (routerId == NatConstants.INVALID_ID) {
LOG.error("createNATFlowEntries : Could not retrieve router id for {} to create NAT Flow entries", routerName);
return;
}
// Check if the router to vpn association is present
// long associatedVpnId = NatUtil.getAssociatedVpn(dataBroker, routerName);
Uuid associatedVpn = NatUtil.getVpnForRouter(dataBroker, routerName);
long associatedVpnId = NatConstants.INVALID_ID;
if (associatedVpn == null) {
LOG.debug("createNATFlowEntries : Router {} is not assicated with any BGP VPN instance", routerName);
} else {
LOG.debug("createNATFlowEntries : Router {} is associated with VPN Instance with Id {}", routerName, associatedVpn);
associatedVpnId = NatUtil.getVpnId(dataBroker, associatedVpn.getValue());
LOG.debug("createNATFlowEntries : vpninstance Id is {} for VPN {}", associatedVpnId, associatedVpn);
// routerId = associatedVpnId;
}
Uuid extNwId = getExtNetworkId(portIid, LogicalDatastoreType.CONFIGURATION);
if (extNwId == null) {
LOG.error("createNATFlowEntries : External network associated with interface {} could not be retrieved", interfaceName);
return;
}
long vpnId = getVpnId(extNwId, mapping.getExternalId());
if (vpnId < 0) {
LOG.error("createNATFlowEntries : No VPN associated with Ext nw {}. Unable to create SNAT table entry " + "for fixed ip {}", extNwId, mapping.getInternalIp());
return;
}
// Install the DNAT default FIB flow L3_FIB_TABLE (21) -> PSNAT_TABLE (26) if SNAT is disabled
boolean isSnatEnabled = NatUtil.isSnatEnabledForRouterId(dataBroker, routerName);
if (!isSnatEnabled) {
addOrDelDefaultFibRouteForDnat(dpnId, routerName, routerId, writeFlowInvTx, true);
}
// Create the DNAT and SNAT table entries
createDNATTblEntry(dpnId, mapping, routerId, associatedVpnId, writeFlowInvTx);
createSNATTblEntry(dpnId, mapping, vpnId, routerId, associatedVpnId, extNwId, writeFlowInvTx);
floatingIPHandler.onAddFloatingIp(dpnId, routerName, routerId, extNwId, interfaceName, mapping, writeFlowInvTx);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnets.associated.to.route.targets.route.target.associated.subnet.AssociatedVpn in project netvirt by opendaylight.
the class VpnManagerImpl method addSubnetAssociationOperationToTx.
private void addSubnetAssociationOperationToTx(String rt, RouteTarget.RtType rtType, String cidr, String vpnName, TypedReadWriteTransaction<Operational> tx, boolean isAssociationRemoved) throws InterruptedException, ExecutionException {
if (isAssociationRemoved) {
// Remove RT-Subnet-Vpn Association
Optional<AssociatedSubnet> associatedSubnet = tx.read(VpnUtil.getAssociatedSubnetIdentifier(rt, rtType, cidr)).get();
boolean deleteParent = false;
if (associatedSubnet.isPresent()) {
List<AssociatedVpn> associatedVpns = new ArrayList<>(associatedSubnet.get().nonnullAssociatedVpn().values());
if (associatedVpns == null || associatedVpns.isEmpty()) {
deleteParent = true;
} else {
for (Iterator<AssociatedVpn> iterator = associatedVpns.iterator(); iterator.hasNext(); ) {
AssociatedVpn associatedVpn = iterator.next();
if (Objects.equals(associatedVpn.getName(), vpnName)) {
iterator.remove();
break;
}
}
if (associatedVpns.isEmpty()) {
deleteParent = true;
}
}
}
if (deleteParent) {
deleteParentForSubnetToVpnAssociation(rt, rtType, cidr, tx);
} else {
// Some other VPNs are also part of this rtVal, rtType and subnetCidr combination.
// Delete only this AssociatedVpn Object
tx.delete(VpnUtil.getAssociatedSubnetAndVpnIdentifier(rt, rtType, cidr, vpnName));
LOG.debug("addSubnetAssocOperationToTx: Removed vpn {} from association rt {} rtType {} cidr {}", vpnName, rt, rtType, cidr);
}
} else {
// Add RT-Subnet-Vpn Association
tx.mergeParentStructurePut(VpnUtil.getAssociatedSubnetAndVpnIdentifier(rt, rtType, cidr, vpnName), VpnUtil.buildAssociatedSubnetAndVpn(vpnName));
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnets.associated.to.route.targets.route.target.associated.subnet.AssociatedVpn in project netvirt by opendaylight.
the class FloatingIPListener method buildPreDNATFlowEntity.
@Nullable
private FlowEntity buildPreDNATFlowEntity(Uint64 dpId, InternalToExternalPortMap mapping, Uint32 routerId, Uint32 associatedVpn) {
String externalIp = mapping.getExternalIp();
Uuid floatingIpId = mapping.getExternalId();
// Get the FIP MAC address for DNAT
String floatingIpPortMacAddress = NatUtil.getFloatingIpPortMacFromFloatingIpId(dataBroker, floatingIpId);
if (floatingIpPortMacAddress == null) {
LOG.error("buildPreDNATFlowEntity : Unable to retrieve floatingIpPortMacAddress from floating IP UUID {} " + "for floating IP {}", floatingIpId, externalIp);
return null;
}
LOG.debug("buildPreDNATFlowEntity : Bulding DNAT Flow entity for ip {} ", externalIp);
Uint32 segmentId = associatedVpn == NatConstants.INVALID_ID ? routerId : associatedVpn;
LOG.debug("buildPreDNATFlowEntity : Segment id {} in build preDNAT Flow", segmentId);
List<MatchInfo> matches = new ArrayList<>();
matches.add(MatchEthernetType.IPV4);
matches.add(new MatchIpv4Destination(externalIp, "32"));
// Match Destination Floating IP MAC Address on table = 25 (PDNAT_TABLE)
matches.add(new MatchEthernetDestination(new MacAddress(floatingIpPortMacAddress)));
// matches.add(new MatchMetadata(
// BigInteger.valueOf(vpnId), MetaDataUtil.METADATA_MASK_VRFID));
List<ActionInfo> actionsInfos = new ArrayList<>();
String internalIp = mapping.getInternalIp();
actionsInfos.add(new ActionSetDestinationIp(internalIp, "32"));
List<InstructionInfo> instructions = new ArrayList<>();
instructions.add(new InstructionWriteMetadata(MetaDataUtil.getVpnIdMetadata(segmentId.longValue()), MetaDataUtil.METADATA_MASK_VRFID));
instructions.add(new InstructionApplyActions(actionsInfos));
instructions.add(new InstructionGotoTable(NwConstants.DNAT_TABLE));
String flowRef = NatUtil.getFlowRef(dpId, NwConstants.PDNAT_TABLE, routerId, externalIp);
FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.PDNAT_TABLE, flowRef, NatConstants.DEFAULT_DNAT_FLOW_PRIORITY, flowRef, 0, 0, NwConstants.COOKIE_DNAT_TABLE, matches, instructions);
return flowEntity;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnets.associated.to.route.targets.route.target.associated.subnet.AssociatedVpn in project netvirt by opendaylight.
the class FloatingIPListener method buildPreDNATFlowEntity.
private FlowEntity buildPreDNATFlowEntity(BigInteger dpId, InternalToExternalPortMap mapping, long routerId, long associatedVpn) {
String externalIp = mapping.getExternalIp();
Uuid floatingIpId = mapping.getExternalId();
// Get the FIP MAC address for DNAT
String floatingIpPortMacAddress = NatUtil.getFloatingIpPortMacFromFloatingIpId(dataBroker, floatingIpId);
if (floatingIpPortMacAddress == null) {
LOG.error("buildPreDNATFlowEntity : Unable to retrieve floatingIpPortMacAddress from floating IP UUID {} " + "for floating IP {}", floatingIpId, externalIp);
return null;
}
LOG.debug("buildPreDNATFlowEntity : Bulding DNAT Flow entity for ip {} ", externalIp);
long segmentId = associatedVpn == NatConstants.INVALID_ID ? routerId : associatedVpn;
LOG.debug("buildPreDNATFlowEntity : Segment id {} in build preDNAT Flow", segmentId);
List<MatchInfo> matches = new ArrayList<>();
matches.add(MatchEthernetType.IPV4);
matches.add(new MatchIpv4Destination(externalIp, "32"));
// Match Destination Floating IP MAC Address on table = 25 (PDNAT_TABLE)
matches.add(new MatchEthernetDestination(new MacAddress(floatingIpPortMacAddress)));
// matches.add(new MatchMetadata(
// BigInteger.valueOf(vpnId), MetaDataUtil.METADATA_MASK_VRFID));
List<ActionInfo> actionsInfos = new ArrayList<>();
String internalIp = mapping.getInternalIp();
actionsInfos.add(new ActionSetDestinationIp(internalIp, "32"));
List<InstructionInfo> instructions = new ArrayList<>();
instructions.add(new InstructionWriteMetadata(MetaDataUtil.getVpnIdMetadata(segmentId), MetaDataUtil.METADATA_MASK_VRFID));
instructions.add(new InstructionApplyActions(actionsInfos));
instructions.add(new InstructionGotoTable(NwConstants.DNAT_TABLE));
String flowRef = NatUtil.getFlowRef(dpId, NwConstants.PDNAT_TABLE, routerId, externalIp);
FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.PDNAT_TABLE, flowRef, NatConstants.DEFAULT_DNAT_FLOW_PRIORITY, flowRef, 0, 0, NwConstants.COOKIE_DNAT_TABLE, matches, instructions);
return flowEntity;
}
Aggregations