use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.RouterId 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.params.xml.ns.yang.bmp.monitor.rev171207.RouterId in project netvirt by opendaylight.
the class InterfaceStateEventListener method getRouterIdForPort.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private String getRouterIdForPort(String interfaceName) {
String routerName = null;
VpnInterface vpnInterface = null;
try {
vpnInterface = NatUtil.getConfiguredVpnInterface(dataBroker, interfaceName);
} catch (Exception ex) {
LOG.error("getRouterIdForPort : Unable to process for interface {} as it is not configured", interfaceName, ex);
}
if (vpnInterface != null) {
// getVpnName
if (vpnInterface.getVpnInstanceNames() == null) {
LOG.debug("getRouterIdForPort : vpnName not found for vpnInterface {} of port {}", vpnInterface, interfaceName);
} else {
for (VpnInstanceNames vpnInstance : vpnInterface.getVpnInstanceNames()) {
String vpnName = vpnInstance.getVpnName();
try {
routerName = NatUtil.getRouterIdfromVpnInstance(dataBroker, vpnName);
} catch (Exception e) {
LOG.error("getRouterIdForPort : Unable to get routerId for vpnName {}", vpnName, e);
}
if (routerName != null) {
// check router is associated to external network
if (NatUtil.isSnatEnabledForRouterId(dataBroker, routerName)) {
LOG.debug("getRouterIdForPort : Retreived Router Id {} for vpnname {} " + "associated to interface {}", routerName, vpnName, interfaceName);
return routerName;
} else {
LOG.warn("getRouterIdForPort : Interface {} associated to routerId {} is not " + "associated to external network", interfaceName, routerName);
}
} else {
LOG.warn("getRouterIdForPort : Router is not associated to vpnname {} for interface {}", vpnName, interfaceName);
}
}
}
} else {
LOG.debug("getRouterIdForPort : Interface {} is not a vpninterface", interfaceName);
}
return null;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.RouterId in project netvirt by opendaylight.
the class InterfaceStateEventListener method removeSnatEntriesForPort.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private void removeSnatEntriesForPort(String interfaceName, String routerName) {
Long routerId = NatUtil.getVpnId(dataBroker, routerName);
if (routerId == NatConstants.INVALID_ID) {
LOG.error("removeSnatEntriesForPort : routerId not found for routername {}", routerName);
return;
}
BigInteger naptSwitch = getNaptSwitchforRouter(dataBroker, routerName);
if (naptSwitch == null || naptSwitch.equals(BigInteger.ZERO)) {
LOG.error("removeSnatEntriesForPort : NaptSwitch is not elected for router {} with Id {}", routerName, routerId);
return;
}
// getInternalIp for port
List<String> fixedIps = getFixedIpsForPort(interfaceName);
if (fixedIps == null) {
LOG.warn("removeSnatEntriesForPort : Internal Ips not found for InterfaceName {} in router {} with id {}", interfaceName, routerName, routerId);
return;
}
for (String internalIp : fixedIps) {
LOG.debug("removeSnatEntriesForPort : Internal Ip retrieved for interface {} is {} in router with Id {}", interfaceName, internalIp, routerId);
IpPort ipPort = NatUtil.getInternalIpPortInfo(dataBroker, routerId, internalIp);
if (ipPort == null) {
LOG.debug("removeSnatEntriesForPort : no snatint-ip-port-map found for ip:{}", internalIp);
continue;
}
for (IntIpProtoType protoType : ipPort.getIntIpProtoType()) {
ProtocolTypes protocol = protoType.getProtocol();
for (Integer portnum : protoType.getPorts()) {
// build and remove the flow in outbound table
try {
removeNatFlow(naptSwitch, NwConstants.OUTBOUND_NAPT_TABLE, routerId, internalIp, portnum);
} catch (Exception ex) {
LOG.error("removeSnatEntriesForPort : Failed to remove snat flow for internalIP {} with " + "Port {} protocol {} for routerId {} in OUTBOUNDTABLE of NaptSwitch {}", internalIp, portnum, protocol, routerId, naptSwitch, ex);
}
// Get the external IP address and the port from the model
NAPTEntryEvent.Protocol proto = protocol.toString().equals(ProtocolTypes.TCP.toString()) ? NAPTEntryEvent.Protocol.TCP : NAPTEntryEvent.Protocol.UDP;
IpPortExternal ipPortExternal = NatUtil.getExternalIpPortMap(dataBroker, routerId, internalIp, String.valueOf(portnum), proto);
if (ipPortExternal == null) {
LOG.error("removeSnatEntriesForPort : Mapping for internalIp {} with port {} is not found in " + "router with Id {}", internalIp, portnum, routerId);
return;
}
String externalIpAddress = ipPortExternal.getIpAddress();
Integer portNumber = ipPortExternal.getPortNum();
// build and remove the flow in inboundtable
try {
removeNatFlow(naptSwitch, NwConstants.INBOUND_NAPT_TABLE, routerId, externalIpAddress, portNumber);
} catch (Exception ex) {
LOG.error("removeSnatEntriesForPort : Failed to remove snat flow internalIP {} with " + "Port {} protocol {} for routerId {} in INBOUNDTABLE of naptSwitch {}", externalIpAddress, portNumber, protocol, routerId, naptSwitch, ex);
}
String internalIpPort = internalIp + ":" + portnum;
// delete the entry from IntExtIpPortMap DS
try {
naptManager.removeFromIpPortMapDS(routerId, internalIpPort, proto);
naptManager.removePortFromPool(internalIpPort, externalIpAddress);
} catch (Exception ex) {
LOG.error("removeSnatEntriesForPort : releaseIpExtPortMapping failed, Removal of " + "ipportmap {} for router {} failed", internalIpPort, routerId, ex);
}
}
}
// delete the entry from SnatIntIpPortMap DS
LOG.debug("removeSnatEntriesForPort : Removing InternalIp:{} on router {}", internalIp, routerId);
naptManager.removeFromSnatIpPortDS(routerId, internalIp);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.RouterId in project netvirt by opendaylight.
the class InterfaceStateEventListener method processInterfaceAdded.
private void processInterfaceAdded(String portName, String routerId, List<ListenableFuture<Void>> futures) {
LOG.trace("processInterfaceAdded : Processing Interface Add Event for interface {}", portName);
List<InternalToExternalPortMap> intExtPortMapList = getIntExtPortMapListForPortName(portName, routerId);
if (intExtPortMapList == null || intExtPortMapList.isEmpty()) {
LOG.debug("processInterfaceAdded : Ip Mapping list is empty/null for portname {}", portName);
return;
}
InstanceIdentifier<RouterPorts> portIid = NatUtil.buildRouterPortsIdentifier(routerId);
WriteTransaction installFlowInvTx = dataBroker.newWriteOnlyTransaction();
for (InternalToExternalPortMap intExtPortMap : intExtPortMapList) {
floatingIPListener.createNATFlowEntries(portName, intExtPortMap, portIid, routerId, installFlowInvTx);
}
// final submit call for installFlowInvTx
futures.add(NatUtil.waitForTransactionToComplete(installFlowInvTx));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.RouterId in project netvirt by opendaylight.
the class NaptEventHandler method prepareAndSendPacketOut.
private void prepareAndSendPacketOut(NAPTEntryEvent naptEntryEvent, Long routerId) {
// Send Packetout - tcp or udp packets which got punted to controller.
BigInteger metadata = naptEntryEvent.getPacketReceived().getMatch().getMetadata().getMetadata();
byte[] inPayload = naptEntryEvent.getPacketReceived().getPayload();
Ethernet ethPkt = new Ethernet();
if (inPayload != null) {
try {
ethPkt.deserialize(inPayload, 0, inPayload.length * NetUtils.NUM_BITS_IN_A_BYTE);
} catch (PacketException e) {
LOG.error("prepareAndSendPacketOut : Failed to decode Packet", e);
return;
}
}
long portTag = MetaDataUtil.getLportFromMetadata(metadata).intValue();
LOG.debug("prepareAndSendPacketOut : portTag from incoming packet is {}", portTag);
String interfaceName = getInterfaceNameFromTag(portTag);
LOG.debug("prepareAndSendPacketOut : interfaceName fetched from portTag is {}", interfaceName);
org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface iface = null;
int vlanId = 0;
iface = interfaceManager.getInterfaceInfoFromConfigDataStore(interfaceName);
if (iface == null) {
LOG.error("prepareAndSendPacketOut : Unable to read interface {} from config DataStore", interfaceName);
return;
}
List<ActionInfo> actionInfos = new ArrayList<>();
IfL2vlan ifL2vlan = iface.getAugmentation(IfL2vlan.class);
if (ifL2vlan != null && ifL2vlan.getVlanId() != null) {
vlanId = ifL2vlan.getVlanId().getValue() == null ? 0 : ifL2vlan.getVlanId().getValue();
}
InterfaceInfo infInfo = interfaceManager.getInterfaceInfoFromOperationalDataStore(interfaceName);
if (infInfo == null) {
LOG.error("prepareAndSendPacketOut : error in getting interfaceInfo from Operation DS");
return;
}
byte[] pktOut = buildNaptPacketOut(ethPkt);
if (ethPkt.getEtherType() != (short) NwConstants.ETHTYPE_802_1Q) {
// VLAN Access port
LOG.debug("prepareAndSendPacketOut : vlanId is {}", vlanId);
if (vlanId != 0) {
// Push vlan
actionInfos.add(new ActionPushVlan(0));
actionInfos.add(new ActionSetFieldVlanVid(1, vlanId));
} else {
LOG.debug("prepareAndSendPacketOut : No vlanId {}, may be untagged", vlanId);
}
} else {
// VLAN Trunk Port
LOG.debug("prepareAndSendPacketOut : This is VLAN Trunk port case - need not do VLAN tagging again");
}
if (pktOut != null) {
String routerName = NatUtil.getRouterName(dataBroker, routerId);
long tunId = NatUtil.getTunnelIdForNonNaptToNaptFlow(dataBroker, elanManager, idManager, routerId, routerName);
sendNaptPacketOut(pktOut, infInfo, actionInfos, tunId);
} else {
LOG.warn("prepareAndSendPacketOut : Unable to send Packet Out");
}
}
Aggregations