return null;
}
- private Long getDpid(Node node) {
+ protected Long getDpid(Node node) {
Long dpid = 0L;
dpid = southbound.getDataPathId(node);
if (dpid == 0) {
import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.AbstractServiceInstance;
import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.OF13Provider;
import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.Service;
+import org.opendaylight.ovsdb.utils.mdsal.openflow.ActionUtils;
import org.opendaylight.ovsdb.utils.mdsal.openflow.InstructionUtils;
import org.opendaylight.ovsdb.utils.mdsal.openflow.MatchUtils;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
import com.google.common.collect.Lists;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg3;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxRegCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
public class InboundNatService extends AbstractServiceInstance implements ConfigInterface, InboundNatProvider {
+ public final static long REG_VALUE_NO_INBOUND_REWRITE = 0x0L;
+ public static final Class<? extends NxmNxReg> REG_FIELD = NxmNxReg3.class;
+
public InboundNatService() {
super(Service.INBOUND_NAT);
}
}
@Override
- public Status programIpRewriteRule(Long dpid, String segmentationId, InetAddress matchAddress,
+ public Status programIpRewriteRule(Long dpid, Long inPort, String destSegId, InetAddress matchAddress,
InetAddress rewriteAddress, Action action) {
String nodeName = Constants.OPENFLOW_NODE_PREFIX + dpid;
List<Instruction> instructions = Lists.newArrayList();
InstructionBuilder ib = new InstructionBuilder();
- MatchUtils.createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId));
+ MatchUtils.createInPortMatch(matchBuilder, dpid, inPort);
MatchUtils.createDstL3IPv4Match(matchBuilder, MatchUtils.iPv4PrefixFromIPv4Address(matchAddress.getHostAddress()));
- // Set Dest IP address
- InstructionUtils.createNwDstInstructions(ib, MatchUtils.iPv4PrefixFromIPv4Address(rewriteAddress.getHostAddress()));
+ // Set register to indicate that rewrite took place
+ ActionBuilder actionBuilder = new ActionBuilder();
+ actionBuilder.setAction(ActionUtils.nxLoadRegAction(new DstNxRegCaseBuilder().setNxReg(REG_FIELD).build(),
+ new BigInteger(destSegId)));
+
+ // Set Dest IP address and set REG_FIELD
+ InstructionUtils.createNwDstInstructions(ib,
+ MatchUtils.iPv4PrefixFromIPv4Address(rewriteAddress.getHostAddress()), actionBuilder);
ib.setOrder(0);
ib.setKey(new InstructionKey(0));
instructions.add(ib.build());
flowBuilder.setMatch(matchBuilder.build());
flowBuilder.setInstructions(isb.setInstruction(instructions).build());
- String flowId = "InboundNAT_" + segmentationId + "_" + rewriteAddress.getHostAddress();
+ String flowId = "InboundNAT_" + inPort + "_" + destSegId + "_" + matchAddress.getHostAddress();
flowBuilder.setId(new FlowId(flowId));
FlowKey key = new FlowKey(new FlowId(flowId));
flowBuilder.setBarrier(true);
return new Status(StatusCode.SUCCESS);
}
+ /**
+ * Program Default Pipeline Flow for Inbound NAT.
+ *
+ * @param node on which the default pipeline flow is programmed.
+ */
+ @Override
+ protected void programDefaultPipelineRule(Node node) {
+ if (!isBridgeInPipeline(node)) {
+ //logger.trace("Bridge is not in pipeline {} ", node);
+ return;
+ }
+ MatchBuilder matchBuilder = new MatchBuilder();
+ FlowBuilder flowBuilder = new FlowBuilder();
+ Long dpid = getDpid(node);
+ if (dpid == 0L) {
+ return;
+ }
+ String nodeName = OPENFLOW + getDpid(node);
+ NodeBuilder nodeBuilder = createNodeBuilder(nodeName);
+
+ // Create the OF Actions and Instructions
+ InstructionsBuilder isb = new InstructionsBuilder();
+
+ // Instructions List Stores Individual Instructions
+ List<Instruction> instructions = Lists.newArrayList();
+
+ // Set register to indicate that rewrite did _not_ take place
+ InstructionBuilder ib = new InstructionBuilder();
+ List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> actionList =
+ Lists.newArrayList();
+ ActionBuilder ab = new ActionBuilder();
+ ab.setAction(ActionUtils.nxLoadRegAction(new DstNxRegCaseBuilder().setNxReg(REG_FIELD).build(),
+ BigInteger.valueOf(REG_VALUE_NO_INBOUND_REWRITE)));
+ ab.setOrder(1);
+ ab.setKey(new ActionKey(1));
+ actionList.add(ab.build());
+
+ ApplyActionsBuilder aab = new ApplyActionsBuilder();
+ aab.setAction(actionList);
+
+ ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
+ ib.setOrder(0);
+ ib.setKey(new InstructionKey(0));
+ instructions.add(ib.build());
+
+ // Call the InstructionBuilder Methods Containing Actions
+ ib = getMutablePipelineInstructionBuilder();
+ ib.setOrder(1);
+ ib.setKey(new InstructionKey(1));
+ instructions.add(ib.build());
+
+ // Add InstructionBuilder to the Instruction(s)Builder List
+ isb.setInstruction(instructions);
+
+ // Add InstructionsBuilder to FlowBuilder
+ flowBuilder.setInstructions(isb.build());
+
+ String flowId = "CUSTOM_DEFAULT_PIPELINE_FLOW_"+getTable();
+ flowBuilder.setId(new FlowId(flowId));
+ FlowKey key = new FlowKey(new FlowId(flowId));
+ flowBuilder.setMatch(matchBuilder.build());
+ flowBuilder.setPriority(0);
+ flowBuilder.setBarrier(true);
+ flowBuilder.setTableId(getTable());
+ flowBuilder.setKey(key);
+ flowBuilder.setFlowName(flowId);
+ flowBuilder.setHardTimeout(0);
+ flowBuilder.setIdleTimeout(0);
+ writeFlow(flowBuilder, nodeBuilder);
+ }
+
@Override
public void setDependencies(BundleContext bundleContext, ServiceReference serviceReference) {
super.setDependencies(bundleContext.getServiceReference(InboundNatProvider.class.getName()), this);
// Set Dest IP address
InstructionUtils.createNwDstInstructions(ib,
- MatchUtils.iPv4PrefixFromIPv4Address(rewriteAddress.getHostAddress()));
+ MatchUtils.iPv4PrefixFromIPv4Address(rewriteAddress.getHostAddress()),
+ null);
ib.setOrder(0);
ib.setKey(new InstructionKey(0));
instructions.add(ib.build());
ActionBuilder ab = new ActionBuilder();
List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> actionList = Lists.newArrayList();
- String prefixString = address.getHostAddress() + "/" + mask;
- MatchUtils.createTunnelIDMatch(matchBuilder, new BigInteger(sourceSegId));
+ if (sourceSegId.equals(Constants.EXTERNAL_NETWORK)) {
+ // If matching on external network, use register reserved for InboundNatService to ensure that
+ // ip rewrite is meant to be consumed by this destination tunnel id.
+ MatchUtils.addNxRegMatch(matchBuilder,
+ new MatchUtils.RegMatch(InboundNatService.REG_FIELD, Long.valueOf(destSegId)));
+ } else {
+ MatchUtils.createTunnelIDMatch(matchBuilder, new BigInteger(sourceSegId));
+ }
+
+ final String prefixString = address.getHostAddress() + "/" + mask;
MatchUtils.createDstL3IPv4Match(matchBuilder, new Ipv4Prefix(prefixString));
// Set source Mac address
flowBuilder.setMatch(matchBuilder.build());
flowBuilder.setInstructions(isb.setInstruction(instructions).build());
- String flowId = "Routing_" + sourceSegId + "_" + prefixString;
+ String flowId = "Routing_" + sourceSegId + "_" + destSegId + "_" + prefixString;
flowBuilder.setId(new FlowId(flowId));
FlowKey key = new FlowKey(new FlowId(flowId));
flowBuilder.setBarrier(true);
}
/**
- * Test method {@link InboundNatService#programIpRewriteRule(Long, String, InetAddress, InetAddress, Action)}
+ * Test method {@link InboundNatService#programIpRewriteRule(Long, Long, InetAddress, InetAddress, Action)}
*/
@Test
public void testProgramIpRewriteRule() throws Exception {
assertEquals("Error, did not return the expected StatusCode",
new Status(StatusCode.SUCCESS),
- inboundNatService.programIpRewriteRule(Long.valueOf(123), "2",
+ inboundNatService.programIpRewriteRule(Long.valueOf(123), Long.valueOf(2), "2", // FIXME: describe params
matchAddress, rewriteAddress, Action.ADD));
verify(writeTransaction, times(2)).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(Node.class), anyBoolean());
verify(writeTransaction, times(1)).submit();
assertEquals("Error, did not return the expected StatusCode",
new Status(StatusCode.SUCCESS),
- inboundNatService.programIpRewriteRule(Long.valueOf(123), "2",
+ inboundNatService.programIpRewriteRule(Long.valueOf(123), Long.valueOf(2), "2", // FIXME: describe params
matchAddress, rewriteAddress, Action.DELETE));
verify(writeTransaction, times(1)).delete(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
verify(writeTransaction, times(2)).submit();
public static final String EXTERNAL_ID_VM_ID = "vm-id";
public static final String EXTERNAL_ID_INTERFACE_ID = "iface-id";
public static final String EXTERNAL_ID_VM_MAC = "attached-mac";
+ public static final String EXTERNAL_NETWORK = "external";
/*
* @see http://docs.openstack.org/grizzly/openstack-network/admin/content/ovs_quantum_plugin.html
* This interface allows NAT flows to be written to devices
*/
public interface InboundNatProvider {
- Status programIpRewriteRule(Long dpid, String segmentationId, InetAddress matchAddress,
+ Status programIpRewriteRule(Long dpid, Long inPort, String destSegId, InetAddress matchAddress,
InetAddress rewriteAddress, Action action);
Status programIpRewriteExclusion(Long dpid, String segmentationId,
private Set<String> inboundIpRewriteCache;
private Set<String> outboundIpRewriteCache;
- private Set<String> inboundIpRewriteExclusionCache;
private Set<String> outboundIpRewriteExclusionCache;
private Set<String> routerInterfacesCache;
private Set<String> staticArpEntryCache;
private void getNeutronL3AdapterFields() throws Exception{
inboundIpRewriteCache = (Set<String>) getField("inboundIpRewriteCache");
outboundIpRewriteCache = (Set<String>) getField("outboundIpRewriteCache");
- inboundIpRewriteExclusionCache = (Set<String>) getField("inboundIpRewriteExclusionCache");
outboundIpRewriteExclusionCache = (Set<String>) getField("outboundIpRewriteExclusionCache");
routerInterfacesCache = (Set<String>) getField("routerInterfacesCache");
staticArpEntryCache = (Set<String>) getField("staticArpEntryCache");
/* TODO SB_MIGRATION */
//assertEquals("Error, did not return the correct routerInterfacesCache size", 2, routerInterfacesCache.size());
// assertEquals("Error, did not return the correct staticArpEntryCache size", 2, staticArpEntryCache.size());
-// assertEquals("Error, did not return the correct inboundIpRewriteExclusionCache size", 1, inboundIpRewriteExclusionCache.size());
// assertEquals("Error, did not return the correct outboundIpRewriteExclusionCache size", 1, outboundIpRewriteExclusionCache.size());
// assertEquals("Error, did not return the correct l3ForwardingCache size", 1, l3ForwardingCache.size());
// Unchanged
// assertEquals("Error, did not return the correct staticArpEntryCache size", 1, staticArpEntryCache.size());
// Unchanged
assertEquals("Error, did not return the correct routerInterfacesCache size", 2, routerInterfacesCache.size());
- assertEquals("Error, did not return the correct inboundIpRewriteExclusionCache size", 1, inboundIpRewriteExclusionCache.size());
assertEquals("Error, did not return the correct outboundIpRewriteExclusionCache size", 1, outboundIpRewriteExclusionCache.size());
assertEquals("Error, did not return the correct l3ForwardingCache size", 1, l3ForwardingCache.size());
assertEquals("Error, did not return the correct inboundIpRewriteCache size", 0, inboundIpRewriteCache.size());
/* TODO SB_MIGRATION */
//assertEquals("Error, did not return the correct routerInterfacesCache size", 2, routerInterfacesCache.size());
assertEquals("Error, did not return the correct staticArpEntryCache size", 2, staticArpEntryCache.size());
- assertEquals("Error, did not return the correct inboundIpRewriteExclusionCache size", 1, inboundIpRewriteExclusionCache.size());
assertEquals("Error, did not return the correct outboundIpRewriteExclusionCache size", 1, outboundIpRewriteExclusionCache.size());
assertEquals("Error, did not return the correct l3ForwardingCache size", 1, l3ForwardingCache.size());
assertEquals("Error, did not return the correct networkIdToRouterMacCache size", 1, networkIdToRouterMacCache.size());
assertEquals("Error, did not return the correct l3ForwardingCache size", 0, l3ForwardingCache.size());
// Unchanged
assertEquals("Error, did not return the correct routerInterfacesCache size", 2, routerInterfacesCache.size());
- assertEquals("Error, did not return the correct inboundIpRewriteExclusionCache size", 1, inboundIpRewriteExclusionCache.size());
assertEquals("Error, did not return the correct outboundIpRewriteExclusionCache size", 1, outboundIpRewriteExclusionCache.size());
assertEquals("Error, did not return the correct networkIdToRouterMacCache size", 1, networkIdToRouterMacCache.size());
assertEquals("Error, did not return the correct inboundIpRewriteCache size", 0, inboundIpRewriteCache.size());
assertEquals("Error, did not return the correct staticArpEntryCache size", 1, staticArpEntryCache.size());
// Unchanged
assertEquals("Error, did not return the correct routerInterfacesCache size", 0, routerInterfacesCache.size());
- assertEquals("Error, did not return the correct inboundIpRewriteExclusionCache size", 0, inboundIpRewriteExclusionCache.size());
assertEquals("Error, did not return the correct outboundIpRewriteExclusionCache size", 0, outboundIpRewriteExclusionCache.size());
assertEquals("Error, did not return the correct subnetIdToRouterInterfaceCache size", 0, subnetIdToRouterInterfaceCache.size());
assertEquals("Error, did not return the correct l3ForwardingCache size", 0, l3ForwardingCache.size());
assertEquals("Error, did not return the correct outboundIpRewriteCache size", 1, outboundIpRewriteCache.size());
assertEquals("Error, did not return the correct staticArpEntryCache size", 1, staticArpEntryCache.size());
assertEquals("Error, did not return the correct routerInterfacesCache size", 0, routerInterfacesCache.size());
- assertEquals("Error, did not return the correct inboundIpRewriteExclusionCache size", 0, inboundIpRewriteExclusionCache.size());
assertEquals("Error, did not return the correct outboundIpRewriteExclusionCache size", 0, outboundIpRewriteExclusionCache.size());
assertEquals("Error, did not return the correct subnetIdToRouterInterfaceCache size", 0, subnetIdToRouterInterfaceCache.size());
assertEquals("Error, did not return the correct l3ForwardingCache size", 0, l3ForwardingCache.size());
*
* @param ib Map InstructionBuilder without any instructions
* @param prefixdst String containing an IPv4 prefix
+ * @param extraAction (optional) Additional action to be performed in actionList
* @return ib Map InstructionBuilder with instructions
*/
- public static InstructionBuilder createNwDstInstructions(InstructionBuilder ib, Ipv4Prefix prefixdst) {
+ public static InstructionBuilder createNwDstInstructions(InstructionBuilder ib, Ipv4Prefix prefixdst,
+ ActionBuilder extraAction) {
List<Action> actionList = Lists.newArrayList();
ActionBuilder ab = new ActionBuilder();
ab.setKey(new ActionKey(0));
actionList.add(ab.build());
+ if (extraAction != null) {
+ extraAction.setOrder(1);
+ extraAction.setKey(new ActionKey(1));
+ actionList.add(extraAction.build());
+ }
+
// Create an Apply Action
ApplyActionsBuilder aab = new ApplyActionsBuilder();
aab.setAction(actionList);