import java.util.concurrent.atomic.AtomicInteger;\r
import java.util.stream.Collectors;\r
\r
+import javax.annotation.Nullable;\r
+\r
import org.apache.commons.net.util.SubnetUtils;\r
import org.opendaylight.controller.md.sal.binding.api.DataBroker;\r
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;\r
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.VppIidFactory;\r
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;\r
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;\r
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;\r
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;\r
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;\r
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.parameters.ExternalIpAddressPool;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.nodes.RendererNode;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.renderers.renderer.renderer.nodes.renderer.node.PhysicalInterface;\r
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;\r
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;\r
import org.slf4j.Logger;\r
import org.slf4j.LoggerFactory;\r
\r
import com.google.common.base.Optional;\r
+\r
public class NatManager {\r
\r
private static final Logger LOG = LoggerFactory.getLogger(NatManager.class);\r
return Optional.of(mappingEntryBuilder);\r
}\r
\r
- public void submitNatChanges(List<InstanceIdentifier<PhysicalInterface>> physIfacesIid,\r
- List<MappingEntryBuilder> natEntries, PolicyContext policyCtx, boolean add) {\r
- LOG.trace("Preparing to submit NAT changes {} on physical interfaces", natEntries.toArray(), physIfacesIid);\r
+ public void submitNatChanges(final List<InstanceIdentifier<PhysicalInterface>> physIfacesIid,\r
+ final @Nullable List<MappingEntryBuilder> sNatEntries,\r
+ final PolicyContext policyCtx,\r
+ final boolean add) {\r
+ if (sNatEntries == null) {\r
+ LOG.trace("No static NAT entries to submit");\r
+ } else{\r
+ LOG.trace("Preparing to submit NAT changes {} on physical interfaces", sNatEntries.toArray(), physIfacesIid);\r
+ }\r
for (InstanceIdentifier<PhysicalInterface> iidPhysIface : physIfacesIid) {\r
- InstanceIdentifier<?> nodeIid = iidPhysIface.firstKeyOf(RendererNode.class).getNodePath();\r
- Optional<DataBroker> mountPointDataBroker = mountDataProvider.getDataBrokerForMountPoint(nodeIid);\r
- if (!mountPointDataBroker.isPresent()) {\r
- throw new IllegalStateException("Cannot find data broker for mount point " + nodeIid);\r
- }\r
+ InstanceIdentifier<Node> nodeIid = (InstanceIdentifier<Node>) iidPhysIface.firstKeyOf(RendererNode.class).getNodePath();\r
String phInterfaceName = iidPhysIface.firstKeyOf(PhysicalInterface.class).getInterfaceName();\r
InstanceIdentifier<Interface> interfaceIID =\r
VppIidFactory.getInterfaceIID(new InterfaceKey(phInterfaceName));\r
\r
Optional<Interface> readIface =\r
- GbpNetconfTransaction.read(mountPointDataBroker.get(), LogicalDatastoreType.CONFIGURATION, interfaceIID,\r
+ GbpNetconfTransaction.read(nodeIid, LogicalDatastoreType.CONFIGURATION, interfaceIID,\r
GbpNetconfTransaction.RETRY_COUNT);\r
\r
if (!readIface.isPresent()) {\r
LOG.error("Interface {} not found on mount point {}", phInterfaceName, nodeIid);\r
- return;\r
+ continue;\r
}\r
if (add) {\r
NatInstance natInstance =\r
- buildNatInstance(natEntries, NatUtil.resolveDynamicNat(policyCtx, natEntries));\r
- GbpNetconfTransaction.netconfSyncedWrite(mountPointDataBroker.get(),\r
+ buildNatInstance(sNatEntries, NatUtil.resolveDynamicNat(policyCtx, sNatEntries));\r
+ GbpNetconfTransaction.netconfSyncedWrite(nodeIid,\r
VppIidFactory.getNatInstanceIid(id), natInstance, GbpNetconfTransaction.RETRY_COUNT);\r
} else {\r
- if (GbpNetconfTransaction.read(mountPointDataBroker.get(), LogicalDatastoreType.CONFIGURATION,\r
+ if (GbpNetconfTransaction.read(nodeIid, LogicalDatastoreType.CONFIGURATION,\r
VppIidFactory.getNatInstanceIid(id), GbpNetconfTransaction.RETRY_COUNT).isPresent()) {\r
- GbpNetconfTransaction.netconfSyncedDelete(mountPointDataBroker.get(),\r
+ GbpNetconfTransaction.netconfSyncedDelete(nodeIid,\r
VppIidFactory.getNatInstanceIid(id), GbpNetconfTransaction.RETRY_COUNT);\r
}\r
}\r
- return;\r
}\r
}\r
\r