import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicInteger;
+import com.google.common.annotations.VisibleForTesting;
import org.opendaylight.groupbasedpolicy.dto.ConditionGroup;
import org.opendaylight.groupbasedpolicy.dto.EgKey;
import org.opendaylight.groupbasedpolicy.dto.EpKey;
return this.cgId;
}
}
+
+ @VisibleForTesting
+ public static void resetPolicyOrdinalValue() {
+ policyOrdinal.set(1);
+ }
}
package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.mapper.egressnat;
import org.opendaylight.groupbasedpolicy.dto.EpKey;
-import org.opendaylight.groupbasedpolicy.dto.IndexedTenant;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfContext;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowTable;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.Endpoint;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayContext;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg6;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg6;
import org.slf4j.LoggerFactory;
-import java.util.Collection;
-
import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.*;
public class EgressNatMapperFlows {
if (natIpSubnet != null && natIpSubnet.getParent() != null) {
L2FloodDomain natEpl2Fd =
ctx.getTenant(natL3Ep.getTenant()).resolveL2FloodDomain(natIpSubnet.getParent());
- if (natEpl2Fd.getAugmentation(Segmentation.class) != null) {
+ if (natEpl2Fd != null && natEpl2Fd.getAugmentation(Segmentation.class) != null) {
Integer vlanId = natEpl2Fd.getAugmentation(Segmentation.class).getSegmentationId();
ofWriter.writeFlow(nodeId, TABLE_ID,
buildPushVlanFlow(natIpAddress.getIpv4Address(), vlanId, 222));
package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.mapper.source;
-import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.addNxTunIdMatch;
-import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.applyActionIns;
-import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.ethernetMatch;
-import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.gotoTableIns;
-import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.instructions;
-import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.nxLoadRegAction;
-import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.nxLoadTunIdAction;
-
-import java.math.BigInteger;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.Sets;
import org.opendaylight.groupbasedpolicy.dto.EgKey;
import org.opendaylight.groupbasedpolicy.dto.IndexedTenant;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfContext;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.endpoint.EndpointManager;
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowIdUtils;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowTable;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.OrdinalFactory;
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.OrdinalFactory.EndpointFwdCtxOrdinals;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action;
-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.Flow;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.go.to.table._case.GoToTable;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.Endpoint;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg5;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg6;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.overlay.rev150105.TunnelTypeVxlan;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import com.google.common.collect.Sets;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
/**
* <h1>Manage the table that assigns source endpoint group, bridge domain, and
* - {@link GoToTable} DESTINATION MAPPER table
*/
public class SourceMapper extends FlowTable {
-
- protected static final Logger LOG = LoggerFactory.getLogger(SourceMapper.class);
-
- // TODO Li alagalah Improve UT coverage for this class.
- public static short TABLE_ID;
+ // Priorities
+ private static final int DROP_ALL = 1;
+ private static final int SYNCHRONIZE_EP = 100;
+ private static final int TUNNEL_FLOW = 151;
+ private static final int BROADCAST_FLOW = 152;
+ private final short tableId;
public SourceMapper(OfContext ctx, short tableId) {
super(ctx);
- TABLE_ID = tableId;
+ this.tableId = tableId;
}
@Override
public short getTableId() {
- return TABLE_ID;
+ return tableId;
}
@Override
public void sync(Endpoint endpoint, OfWriter ofWriter) throws Exception {
-
- // TODO: only temporary workaround, use src & dst endpoint in implementation
- NodeId nodeId = ctx.getEndpointManager().getEndpointNodeId(endpoint);
-
- ofWriter.writeFlow(nodeId, TABLE_ID, dropFlow(Integer.valueOf(1), null, TABLE_ID));
-
- // Handle case where packets from from External
- for (Endpoint ep : ctx.getEndpointManager().getEndpointsForNode(nodeId)) {
- IndexedTenant tenant = ctx.getTenant(ep.getTenant());
- if (tenant == null)
- continue;
-
- EndpointFwdCtxOrdinals epFwdCtxOrds = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, ep);
- if (epFwdCtxOrds == null) {
- LOG.debug("getEndpointFwdCtxOrdinals is null for EP {}", ep);
- continue;
- }
-
- createRemoteTunnels(ofWriter, nodeId, ep, epFwdCtxOrds);
-
- if (ep.getTenant() == null || (ep.getEndpointGroup() == null && ep.getEndpointGroups() == null)) {
- continue;
- }
-
- OfOverlayContext ofc = ep.getAugmentation(OfOverlayContext.class);
- if (ofc != null && ofc.getNodeConnectorId() != null
- && (EndpointManager.isInternal(ep, ctx.getTenant(ep.getTenant()).getExternalImplicitGroups()))) {
-
- // Sync the local EP information
- syncEP(ofWriter, nodeId, ep, ofc.getNodeConnectorId(), epFwdCtxOrds);
- }
+ NodeId endpointNodeId = ctx.getEndpointManager().getEndpointNodeId(endpoint);
+ if (endpointNodeId == null) {
+ LOG.warn("Endpoint {} has no location specified, skipped", endpoint);
+ return;
}
+ SourceMapperFlows flows = new SourceMapperFlows(endpointNodeId, tableId);
+ syncFlows(flows, endpoint, endpointNodeId, ofWriter);
}
- private void createRemoteTunnels(OfWriter ofWriter, NodeId nodeId, Endpoint ep, EndpointFwdCtxOrdinals epFwdCtxOrds)
- throws Exception {
- Set<EgKey> epgs = new HashSet<>();
-
- // Get EPGs and add to Set to remove duplicates
- // TODO alagalah Li: test EndpointManager.getEgKeys
- if (ep.getEndpointGroup() != null) {
- epgs.add(new EgKey(ep.getTenant(), ep.getEndpointGroup()));
- }
- if (ep.getEndpointGroups() != null) {
- for (EndpointGroupId epgId : ep.getEndpointGroups()) {
- epgs.add(new EgKey(ep.getTenant(), epgId));
- }
- }
-
- // Create tunnels on remote Nodes that may talk to us.
- for (EgKey epg : epgs) {
- Set<EgKey> peers = Sets.union(Collections.singleton(epg), ctx.getCurrentPolicy().getPeers(epg));
- for (EgKey peer : peers) {
- for (NodeId remoteNodeId : ctx.getEndpointManager().getNodesForGroup(peer)) {
-
- // Please do not check for remote v local nodeID, we need local to local tunnels
- // in the case of chaining - The Great Dr Sunal.
- NodeConnectorId tunPort = ctx.getSwitchManager().getTunnelPort(remoteNodeId, TunnelTypeVxlan.class);
- if (tunPort == null) {
- LOG.trace("No tunnel port for tunnel in SourceMapper between local:{} and remote:{}",
- nodeId.getValue(), remoteNodeId.getValue());
- continue;
+ @VisibleForTesting
+ void syncFlows(SourceMapperFlows flows, Endpoint endpoint, NodeId nodeId, OfWriter ofWriter) {
+
+ // Basic drop all flow
+ flows.dropFlow(DROP_ALL, null, ofWriter);
+
+ // Create remote tunnel/broadcast flows
+ short destinationMapperId = ctx.getPolicyManager().getTABLEID_DESTINATION_MAPPER();
+ NodeConnectorId tunnelPort = ctx.getSwitchManager().getTunnelPort(nodeId, TunnelTypeVxlan.class);
+ if (tunnelPort != null) {
+ // Get all original endpoint groups
+ Set<EgKey> endpointGroups = getEndpointGroups(endpoint);
+ for (EgKey endpointGroup : endpointGroups) {
+ // Get all original endpoint peers
+ Set<EgKey> peers = Sets.union(Collections.singleton(endpointGroup),
+ ctx.getCurrentPolicy().getPeers(endpointGroup));
+ for (EgKey peer : peers) {
+ Collection<Endpoint> peerEgEndpoints = ctx.getEndpointManager().getEndpointsForGroup(peer);
+ for (Endpoint peerEgEndpoint : peerEgEndpoints) {
+ OrdinalFactory.EndpointFwdCtxOrdinals ordinals = getEndpointOrdinals(ctx, peerEgEndpoint);
+ flows.createTunnelFlow(destinationMapperId, TUNNEL_FLOW, tunnelPort, ordinals,
+ ofWriter);
+ flows.createBroadcastFlow(destinationMapperId, BROADCAST_FLOW, tunnelPort,
+ ordinals, ofWriter);
}
- ofWriter.writeFlow(remoteNodeId, TABLE_ID, createTunnelFlow(tunPort, epFwdCtxOrds));
- ofWriter.writeFlow(remoteNodeId, TABLE_ID, createBroadcastFlow(tunPort, epFwdCtxOrds));
}
}
}
- }
-
- private Flow createBroadcastFlow(NodeConnectorId tunPort, EndpointFwdCtxOrdinals epFwdCtxOrds) {
- int fdId = epFwdCtxOrds.getFdId();
-
- MatchBuilder mb = new MatchBuilder().setInPort(tunPort);
- addNxTunIdMatch(mb, fdId);
-
- // set condition group register to all ones to
- // bypass
- // policy enforcement
- /*
- * TODO: This breaks distributed policy enforcement
- * especially wrt multi-action. BAD. Must be addressed
- * (this is why we can't have nice things).
- * This can be fixed with new tunnelId ordinal in
- * Ordinal Factory.
- */
-
- Action fdReg = nxLoadRegAction(NxmNxReg5.class, BigInteger.valueOf(fdId));
-
- Match match = mb.build();
- FlowId flowid = FlowIdUtils.newFlowId(TABLE_ID, "tunnelFdId", match);
- FlowBuilder flowb = base().setId(flowid)
- .setPriority(Integer.valueOf(150))
- .setMatch(match)
- .setInstructions(instructions(applyActionIns(fdReg), gotoTableIns(ctx.getPolicyManager().getTABLEID_DESTINATION_MAPPER())));
- return flowb.build();
+ if (endpoint.getEndpointGroup() == null && endpoint.getEndpointGroups() == null || endpoint.getTenant() == null) {
+ return;
+ }
+ IndexedTenant tenant = ctx.getTenant(endpoint.getTenant());
+ // Sync the local EP information
+ OrdinalFactory.EndpointFwdCtxOrdinals endpointFwdCtxOrdinals = getEndpointOrdinals(ctx, endpoint);
+ MacAddress macAddress = endpoint.getMacAddress();
+ if (endpointFwdCtxOrdinals != null) {
+ OfOverlayContext ofOverlayContext = endpoint.getAugmentation(OfOverlayContext.class);
+ if (ofOverlayContext != null && ofOverlayContext.getNodeConnectorId() != null &&
+ (EndpointManager.isInternal(endpoint, tenant.getExternalImplicitGroups()))) {
+ flows.synchronizeEp(destinationMapperId, SYNCHRONIZE_EP, endpointFwdCtxOrdinals, macAddress,
+ ofOverlayContext.getNodeConnectorId(), ofWriter);
+ }
+ }
}
- private Flow createTunnelFlow(NodeConnectorId tunPort, EndpointFwdCtxOrdinals epFwdCtxOrds) {
- // ... this is a remote node.
-
- int egId = epFwdCtxOrds.getEpgId();
- int bdId = epFwdCtxOrds.getBdId();
- int fdId = epFwdCtxOrds.getFdId();
- int l3Id = epFwdCtxOrds.getL3Id();
- int tunnelId = epFwdCtxOrds.getTunnelId();
-
- MatchBuilder mb = new MatchBuilder().setInPort(tunPort);
- addNxTunIdMatch(mb, tunnelId);
-
- Action segReg = nxLoadRegAction(NxmNxReg0.class, BigInteger.valueOf(egId));
- // set condition group register to all ones to
- // bypass
- // policy enforcement
- /*
- * TODO: This breaks distributed policy enforcement
- * especially wrt multi-action. BAD. Must be addressed
- * (this is why we can't have nice things).
- * This can be fixed with new tunnelId ordinal in
- * Ordinal Factory.
- */
- Action scgReg = nxLoadRegAction(NxmNxReg1.class, BigInteger.valueOf(0xffffff));
- Action bdReg = nxLoadRegAction(NxmNxReg4.class, BigInteger.valueOf(bdId));
- Action fdReg = nxLoadRegAction(NxmNxReg5.class, BigInteger.valueOf(fdId));
- Action vrfReg = nxLoadRegAction(NxmNxReg6.class, BigInteger.valueOf(l3Id));
- Match match = mb.build();
- FlowId flowid = FlowIdUtils.newFlowId(TABLE_ID, "tunnel", match);
- FlowBuilder flowb = base().setId(flowid)
- .setPriority(Integer.valueOf(150))
- .setMatch(match)
- .setInstructions(
- instructions(applyActionIns(segReg, scgReg, bdReg, fdReg, vrfReg),
- gotoTableIns(ctx.getPolicyManager().getTABLEID_DESTINATION_MAPPER())));
- return flowb.build();
+ private OrdinalFactory.EndpointFwdCtxOrdinals getEndpointOrdinals(OfContext ctx, Endpoint endpoint) {
+ try {
+ return OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, endpoint);
+ } catch (Exception e) {
+ LOG.error("Failed to get fwd ctx ordinals for endpoint {}", endpoint);
+ return null;
+ }
}
- private void syncEP(OfWriter ofWriter, NodeId nodeId, Endpoint ep, NodeConnectorId ncId, EndpointFwdCtxOrdinals epFwdCtxOrds) throws Exception {
-
- // TODO alagalah Li/Be: We should also match on EndpointL3 with the appropriate
- // network containment. This would solve a lot of problems and prepare for EndpointL3 RPC.
-
- int egId = epFwdCtxOrds.getEpgId();
- int bdId = epFwdCtxOrds.getBdId();
- int fdId = epFwdCtxOrds.getFdId();
- int l3Id = epFwdCtxOrds.getL3Id();
- int cgId = epFwdCtxOrds.getCgId();
- int tunnelId = epFwdCtxOrds.getTunnelId();
-
- Action segReg = nxLoadRegAction(NxmNxReg0.class, BigInteger.valueOf(egId));
- Action scgReg = nxLoadRegAction(NxmNxReg1.class, BigInteger.valueOf(cgId));
- Action bdReg = nxLoadRegAction(NxmNxReg4.class, BigInteger.valueOf(bdId));
- Action fdReg = nxLoadRegAction(NxmNxReg5.class, BigInteger.valueOf(fdId));
- Action vrfReg = nxLoadRegAction(NxmNxReg6.class, BigInteger.valueOf(l3Id));
- Action tunIdAction = nxLoadTunIdAction(BigInteger.valueOf(tunnelId), false);
+ private Set<EgKey> getEndpointGroups(Endpoint endpoint) {
+ Set<EgKey> endpointGroups = new HashSet<>();
+ if (endpoint.getEndpointGroup() != null) {
+ endpointGroups.add(new EgKey(endpoint.getTenant(), endpoint.getEndpointGroup()));
+ }
+ if (endpoint.getEndpointGroups() != null) {
+ for (EndpointGroupId epgId : endpoint.getEndpointGroups()) {
+ endpointGroups.add(new EgKey(endpoint.getTenant(), epgId));
+ }
+ }
- Match match = new MatchBuilder().setEthernetMatch(ethernetMatch(ep.getMacAddress(), null, null))
- .setInPort(ncId)
- .build();
- FlowId flowid = FlowIdUtils.newFlowId(TABLE_ID, "ep", match);
- FlowBuilder flowb = base().setPriority(Integer.valueOf(100))
- .setId(flowid)
- .setMatch(match)
- .setInstructions(
- instructions(applyActionIns(segReg, scgReg, bdReg, fdReg, vrfReg,tunIdAction),
- gotoTableIns(ctx.getPolicyManager().getTABLEID_DESTINATION_MAPPER())));
- ofWriter.writeFlow(nodeId, TABLE_ID, flowb.build());
+ return endpointGroups;
}
-
}
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.mapper.source;
+
+import com.google.common.base.Preconditions;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowIdUtils;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.OrdinalFactory;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action;
+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.types.rev131026.flow.Match;
+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.go.to.table._case.GoToTable;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.Endpoint;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg0;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg4;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg5;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg6;
+
+import java.math.BigInteger;
+
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.*;
+
+public class SourceMapperFlows {
+
+ private final NodeId nodeId;
+ private final short tableId;
+
+ public SourceMapperFlows(NodeId nodeId, short tableId) {
+ this.nodeId = Preconditions.checkNotNull(nodeId);
+ this.tableId = tableId;
+ }
+
+ /**
+ * Default flow which drops all traffic
+ *
+ * @param priority of flow in the table
+ * @param etherType can be set as specific protocol to match
+ * @param ofWriter flow writer
+ */
+ void dropFlow(int priority, Long etherType, OfWriter ofWriter) {
+ FlowId flowId;
+ FlowBuilder flowBuilder = FlowUtils.base(tableId)
+ .setPriority(priority)
+ .setInstructions(FlowUtils.dropInstructions());
+ if (etherType != null) {
+ MatchBuilder matchBuilder = new MatchBuilder()
+ .setEthernetMatch(FlowUtils.ethernetMatch(null, null, etherType));
+ Match match = matchBuilder.build();
+ flowId = FlowIdUtils.newFlowId(tableId, "drop", match);
+ flowBuilder.setMatch(match);
+ } else {
+ flowId = FlowIdUtils.newFlowId("dropAll");
+ }
+ flowBuilder.setId(flowId);
+ ofWriter.writeFlow(nodeId, tableId, flowBuilder.build());
+ }
+
+ /**
+ * Load endpoint ordinals to registers and set tunnel ID value (when exists). Traffic is redirected to destination
+ * mapper
+ *
+ * @param goToTable table ID for {@link GoToTable} instruction
+ * @param priority of the flow
+ * @param ordinals ordinals of the {@link Endpoint}
+ * @param macAddress of the endpoint
+ * @param nodeConnectorId of endpoint openflow port
+ * @param ofWriter flow writer
+ */
+ public void synchronizeEp(short goToTable, int priority, OrdinalFactory.EndpointFwdCtxOrdinals ordinals,
+ MacAddress macAddress, NodeConnectorId nodeConnectorId, OfWriter ofWriter) {
+ int egId = ordinals.getEpgId();
+ int bdId = ordinals.getBdId();
+ int fdId = ordinals.getFdId();
+ int l3Id = ordinals.getL3Id();
+ int cgId = ordinals.getCgId();
+ int tunnelId = ordinals.getTunnelId();
+
+ Action segReg = nxLoadRegAction(NxmNxReg0.class, BigInteger.valueOf(egId));
+ Action scgReg = nxLoadRegAction(NxmNxReg1.class, BigInteger.valueOf(cgId));
+ Action bdReg = nxLoadRegAction(NxmNxReg4.class, BigInteger.valueOf(bdId));
+ Action fdReg = nxLoadRegAction(NxmNxReg5.class, BigInteger.valueOf(fdId));
+ Action vrfReg = nxLoadRegAction(NxmNxReg6.class, BigInteger.valueOf(l3Id));
+ Action tunIdAction = nxLoadTunIdAction(BigInteger.valueOf(tunnelId), false);
+
+ Match match = new MatchBuilder().setEthernetMatch(ethernetMatch(macAddress, null, null))
+ .setInPort(nodeConnectorId)
+ .build();
+ FlowId flowid = FlowIdUtils.newFlowId(tableId, "ep", match);
+ FlowBuilder flowBuilder = base(tableId).setPriority(priority)
+ .setId(flowid)
+ .setMatch(match)
+ .setInstructions(
+ instructions(applyActionIns(segReg, scgReg, bdReg, fdReg, vrfReg, tunIdAction),
+ gotoTableIns(goToTable)));
+ ofWriter.writeFlow(nodeId, tableId, flowBuilder.build());
+ }
+
+ /**
+ * Writes remote tunnel flows. Is evaluated, for which nodes this one acts as a remote node. Then using their
+ * ordinals, tunnel flow is written on this node
+ *
+ * @param goToTable table ID for {@link GoToTable} instruction
+ * @param priority of the flow
+ * @param tunnel port number
+ * @param remoteOrdinals ordinals of remote node
+ * @param ofWriter flow writer
+ */
+ public void createTunnelFlow(short goToTable, int priority, NodeConnectorId tunnel,
+ OrdinalFactory.EndpointFwdCtxOrdinals remoteOrdinals, OfWriter ofWriter) {
+ int egId = remoteOrdinals.getEpgId();
+ int bdId = remoteOrdinals.getBdId();
+ int fdId = remoteOrdinals.getFdId();
+ int l3Id = remoteOrdinals.getL3Id();
+ int tunnelId = remoteOrdinals.getTunnelId();
+
+ MatchBuilder matchBuilder = new MatchBuilder().setInPort(tunnel);
+ addNxTunIdMatch(matchBuilder, tunnelId);
+
+ Action segReg = nxLoadRegAction(NxmNxReg0.class, BigInteger.valueOf(egId));
+ Action scgReg = nxLoadRegAction(NxmNxReg1.class, BigInteger.valueOf(0xffffff));
+ Action bdReg = nxLoadRegAction(NxmNxReg4.class, BigInteger.valueOf(bdId));
+ Action fdReg = nxLoadRegAction(NxmNxReg5.class, BigInteger.valueOf(fdId));
+ Action vrfReg = nxLoadRegAction(NxmNxReg6.class, BigInteger.valueOf(l3Id));
+ Match match = matchBuilder.build();
+ FlowId flowId = FlowIdUtils.newFlowId(tableId, "tunnel", match);
+ FlowBuilder flowBuilder = base(tableId).setId(flowId)
+ .setPriority(priority)
+ .setMatch(match)
+ .setInstructions(
+ instructions(applyActionIns(segReg, scgReg, bdReg, fdReg, vrfReg), gotoTableIns(goToTable)));
+ ofWriter.writeFlow(nodeId, tableId, flowBuilder.build());
+ }
+
+ /**
+ * Writes remote broadcast flows. Is evaluated, for which nodes this one acts as a remote node. Then using their
+ * ordinals, broadcast flow is written on this node
+ *
+ * @param goToTable table ID for {@link GoToTable} instruction
+ * @param priority of the flow
+ * @param tunnel port number
+ * @param remoteOrdinals ordinals of remote node
+ * @param ofWriter flow writer
+ */
+ public void createBroadcastFlow(short goToTable, int priority, NodeConnectorId tunnel,
+ OrdinalFactory.EndpointFwdCtxOrdinals remoteOrdinals, OfWriter ofWriter) {
+ int fdId = remoteOrdinals.getFdId();
+
+ MatchBuilder matchBuilder = new MatchBuilder().setInPort(tunnel);
+ addNxTunIdMatch(matchBuilder, fdId);
+
+ Action fdReg = nxLoadRegAction(NxmNxReg5.class, BigInteger.valueOf(fdId));
+
+ Match match = matchBuilder.build();
+ FlowId flowId = FlowIdUtils.newFlowId(tableId, "tunnelFdId", match);
+ FlowBuilder flowBuilder = base(tableId).setId(flowId)
+ .setPriority(priority)
+ .setMatch(match)
+ .setInstructions(instructions(applyActionIns(fdReg), gotoTableIns(goToTable)));
+ ofWriter.writeFlow(nodeId, tableId, flowBuilder.build());
+ }
+}
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow;
-
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.opendaylight.groupbasedpolicy.dto.EgKey;
-import org.opendaylight.groupbasedpolicy.dto.IndexedTenant;
-import org.opendaylight.groupbasedpolicy.dto.PolicyInfo;
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfContext;
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.PolicyManager;
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.endpoint.EndpointManager;
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.mapper.source.SourceMapper;
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.node.SwitchManager;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.Endpoint;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayContext;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.EndpointGroup;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.overlay.rev150105.TunnelTypeVxlan;
-
-public class SourceMapperTest {
-
- private SourceMapper mapper;
-
- private OfContext ctx;
- private short tableId;
- private NodeId nodeId;
- private PolicyInfo policyInfo;
- private OfWriter ofWriter;
- private Endpoint endpoint;
- private EndpointManager endpointManager;
- private IndexedTenant tenant;
- private TenantId tenantId;
- private PolicyManager policyManager;
- private OfOverlayContext ofOverlayContext;
- private NodeConnectorId nodeConnectorId;
- private EndpointGroupId endpointGroupIdSingle;
- private EndpointGroupId endpointGroupIdList;
- private EndpointGroup endpointGroup;
- private SwitchManager switchManager;
-
- @Before
- public void initialisation() {
- ctx = mock(OfContext.class);
- tableId = 5;
- nodeId = mock(NodeId.class);
- ofWriter = mock(OfWriter.class);
-
- mapper = new SourceMapper(ctx, tableId);
-
- endpointManager = mock(EndpointManager.class);
- when(ctx.getEndpointManager()).thenReturn(endpointManager);
- endpoint = mock(Endpoint.class);
- List<Endpoint> endpointsForNode = Arrays.asList(endpoint);
- when(endpointManager.getEndpointsForNode(nodeId)).thenReturn(endpointsForNode);
-
- ofOverlayContext = mock(OfOverlayContext.class);
- when(endpoint.getAugmentation(OfOverlayContext.class)).thenReturn(ofOverlayContext);
- nodeConnectorId = mock(NodeConnectorId.class);
- when(ofOverlayContext.getNodeConnectorId()).thenReturn(nodeConnectorId);
-
- tenantId = mock(TenantId.class);
- when(endpoint.getTenant()).thenReturn(tenantId);
- tenant = mock(IndexedTenant.class);
- when(ctx.getTenant(tenantId)).thenReturn(tenant);
- policyManager = mock(PolicyManager.class);
- when(ctx.getPolicyManager()).thenReturn(policyManager);
- policyInfo = mock(PolicyInfo.class);
- when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
-
- endpointGroup = mock(EndpointGroup.class);
- when(tenant.getEndpointGroup(any(EndpointGroupId.class))).thenReturn(endpointGroup);
-
- Set<NodeId> nodeIdPeers = new HashSet<NodeId>(Arrays.asList(nodeId));
- when(endpointManager.getNodesForGroup(any(EgKey.class))).thenReturn(nodeIdPeers);
-
- switchManager = mock(SwitchManager.class);
- when(ctx.getSwitchManager()).thenReturn(switchManager);
- when(switchManager.getTunnelPort(nodeId, TunnelTypeVxlan.class)).thenReturn(nodeConnectorId);
- }
-
- @Test
- public void constructorTest() {
- Assert.assertEquals(tableId, mapper.getTableId());
- }
-
- @Ignore
- @Test
- public void syncTestEndpointGroup() throws Exception {
- endpointGroupIdSingle = mock(EndpointGroupId.class);
- when(endpoint.getEndpointGroup()).thenReturn(endpointGroupIdSingle);
- when(endpoint.getEndpointGroups()).thenReturn(null);
-
- //mapper.sync(nodeId, ofWriter);
- verify(ofWriter, times(4)).writeFlow(any(NodeId.class), any(Short.class), any(Flow.class));
- }
-
- @Ignore
- @Test
- public void syncTestEndpointGroups() throws Exception {
- endpointGroupIdList = mock(EndpointGroupId.class);
- List<EndpointGroupId> endpointGroups = Arrays.asList(endpointGroupIdList);
- when(endpoint.getEndpointGroups()).thenReturn(endpointGroups);
-
- //mapper.sync(nodeId, ofWriter);
- verify(ofWriter, times(4)).writeFlow(any(NodeId.class), any(Short.class), any(Flow.class));
- }
-
- @Ignore
- @Test
- public void syncTestEndpointGroupPeers() throws Exception {
- endpointGroupIdSingle = mock(EndpointGroupId.class);
- when(endpoint.getEndpointGroup()).thenReturn(endpointGroupIdSingle);
- when(endpoint.getEndpointGroups()).thenReturn(null);
-
- //mapper.sync(nodeId, ofWriter);
- verify(ofWriter, times(4)).writeFlow(any(NodeId.class), any(Short.class), any(Flow.class));
- }
-
- @Ignore
- @Test
- public void syncTestEndpointGroupTunPortNull() throws Exception {
- endpointGroupIdSingle = mock(EndpointGroupId.class);
- when(endpoint.getEndpointGroup()).thenReturn(endpointGroupIdSingle);
- when(endpoint.getEndpointGroups()).thenReturn(null);
- when(switchManager.getTunnelPort(nodeId, TunnelTypeVxlan.class)).thenReturn(null);
-
- //mapper.sync(nodeId, ofWriter);
- verify(ofWriter, times(2)).writeFlow(any(NodeId.class), any(Short.class), any(Flow.class));
- }
-
- @Ignore
- @Test
- public void syncTestTenantNull() throws Exception {
- when(ctx.getTenant(tenantId)).thenReturn(null);
-
- //mapper.sync(nodeId, ofWriter);
- verify(ofWriter, times(1)).writeFlow(any(NodeId.class), any(Short.class), any(Flow.class));
- }
-}
-package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.mapper;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.opendaylight.groupbasedpolicy.api.sf.L4ClassifierDefinition;
-import org.opendaylight.groupbasedpolicy.dto.IndexedTenant;
-import org.opendaylight.groupbasedpolicy.dto.PolicyInfo;
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfContext;
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.PolicyManager;
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.endpoint.EndpointManager;
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowTable;
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils;
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.node.SwitchManager;
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf.AllowAction;
-import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf.Classifier;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
-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.Flow;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ActionName;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ClassifierName;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ContractId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L2BridgeDomainId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L2FloodDomainId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L3ContextId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.NetworkDomainId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ParameterName;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.SelectorName;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.SubnetId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoint.fields.L3Address;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoint.fields.L3AddressBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.Endpoint;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.l3endpoint.rev151217.NatAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.l3endpoint.rev151217.NatAddressBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayContext;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayContextBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.Segmentation;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.SegmentationBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValueBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.TenantBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.ForwardingContextBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.PolicyBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L2BridgeDomainBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L2FloodDomain;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L2FloodDomainBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L3ContextBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.SubnetBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.EndpointGroupBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.SubjectFeatureInstancesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.endpoint.group.ConsumerNamedSelectorBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.endpoint.group.ProviderNamedSelectorBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.subject.feature.instances.ActionInstanceBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.subject.feature.instances.ClassifierInstanceBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
-
-import com.google.common.collect.ImmutableList;
-
-public abstract class MapperUtilsTest {
-
- protected static final String IPV4_1 = "170.0.0.1";
- protected static final String IPV4_2 = "190.0.0.1";
- protected static final String MAC_0 = "00:00:00:00:00:00";
- protected static final String MAC_1 = "00:00:00:00:00:01";
- protected static final String CONNECTOR_0 = "0";
- protected static final String CONNECTOR_1 = "1";
- protected static final String IP_PREFIX_32 = "/32";
- protected static final String IP_PREFIX_128 = "/128";
- protected static final String IPV6_1 = "2000:db80:85a3:08ba:0947:8a2e:3a70:7334";
- protected static final String IPV6_2 = "0947:db80:3a70:7334:85a3:8a2e:2000:08ba";
- protected static final String DHCP_IP = "255.255.255.255";
- protected static final String TENANT_ID = "dummy tenant";
- protected static final String NODE_ID = "dummy node";
- protected static final String CONTRACT_ID = "dummy contract";
- protected static final String L2 = "L2";
- protected static final String DOMAIN_ID = "dummy id";
- protected final NodeId nodeId = new NodeId(NODE_ID);
- protected NodeConnectorId nodeConnectorId =
- new NodeConnectorId(nodeId.getValue() + CONNECTOR_0);
- protected L3ContextId l3c = new L3ContextId("2cf51ee4-e996-467e-a277-2d380334a91d");
- protected L2BridgeDomainId bd = new L2BridgeDomainId("c95182ba-7807-43f8-98f7-6c7c720b7639");
- protected L2FloodDomainId fd = new L2FloodDomainId("98e1439e-52d2-46f8-bd69-5136e6088771");
- protected L2FloodDomainId ext_fd = new L2FloodDomainId("d8024f7a-b83e-11e5-9912-ba0be0483c18");
- protected SubnetId sub = new SubnetId("4fcf8dfc-53b5-4aef-84d3-6b5586992fcb");
- protected SubnetId sub2 = new SubnetId("c285a59f-fcb8-42e6-bf29-87ea522fd626");
- protected SubnetId sub3 = new SubnetId("a0380d52-2a25-48ef-882c-a4d4cd9e00ec");
- protected SubnetId ext_sub = new SubnetId("8da17ad9-3261-4dc9-bcff-928a2f73cce7");
- protected TenantId tid = new TenantId(TENANT_ID);
- protected EndpointGroupId eg = new EndpointGroupId("36dec84a-08c7-497b-80b6-a0035af72a12");
- protected EndpointGroupId eg2 = new EndpointGroupId("632e5e11-7988-4eb5-8fe6-6c182d890276");
- protected ContractId cid = new ContractId("a5874893-bcd5-46de-96af-3c8d99bedf9f");
- protected Short tableId;
- protected OfContext ctx;
- protected OfWriter ofWriter;
- protected SwitchManager switchManager;
- protected PolicyManager policyManager;
- protected EndpointManager endpointManager;
- protected PolicyInfo policyInfo;
- protected FlowTable table;
-
- protected Flow flowCreator(FlowId flowId, short tableId, Integer priority, Match match, Instructions instructions) {
- FlowBuilder flowBuilder = FlowUtils.base(tableId);
- flowBuilder.setId(flowId)
- .setPriority(priority)
- .setMatch(match)
- .setInstructions(instructions);
-
- return flowBuilder.build();
- }
-
- protected Endpoint endpointCreator(IpAddress ip, MacAddress mac, NodeConnectorId nodeConnectorId) {
- EndpointBuilder endpointBuilder = new EndpointBuilder();
-
- // Set tenant
- endpointBuilder.setTenant(new TenantId(TENANT_ID));
-
- // Set L3 address
- if (ip != null) {
- List<L3Address> l3Addresses = new ArrayList<>();
- L3AddressBuilder l3AddressBuilder = new L3AddressBuilder();
- l3AddressBuilder.setIpAddress(ip);
- l3Addresses.add(l3AddressBuilder.build());
- endpointBuilder.setL3Address(l3Addresses);
- }
-
- // Set Mac address
- endpointBuilder.setMacAddress(new MacAddress(mac));
-
- // Augment node connector
- OfOverlayContextBuilder ofOverlayContextBuilder = new OfOverlayContextBuilder();
- ofOverlayContextBuilder.setNodeConnectorId(new NodeConnectorId(nodeConnectorId));
- ofOverlayContextBuilder.setNodeId(nodeId);
- endpointBuilder.addAugmentation(OfOverlayContext.class, ofOverlayContextBuilder.build());
-
- // Set network containment
- endpointBuilder.setNetworkContainment(new NetworkDomainId(DOMAIN_ID));
-
- return endpointBuilder.build();
- }
-
- protected EndpointL3 endpointL3Creator(String ip, String insideIp, String mac, String l2, boolean ipv6) {
- EndpointL3Builder endpointL3Builder = new EndpointL3Builder();
-
- // Set NAT address augmentation
- if (ip != null) {
- if (ipv6) {
- NatAddressBuilder natAddressBuilder = new NatAddressBuilder();
- natAddressBuilder.setNatAddress(new IpAddress(new Ipv6Address(ip)));
- endpointL3Builder.addAugmentation(NatAddress.class, natAddressBuilder.build());
- } else {
- NatAddressBuilder natAddressBuilder = new NatAddressBuilder();
- natAddressBuilder.setNatAddress(new IpAddress(new Ipv4Address(ip)));
- endpointL3Builder.addAugmentation(NatAddress.class, natAddressBuilder.build());
- }
- }
-
- // Set IP address
- if (insideIp != null) {
- if (ipv6) {
- endpointL3Builder.setIpAddress(new IpAddress(new Ipv6Address(insideIp)));
- } else {
- endpointL3Builder.setIpAddress(new IpAddress(new Ipv4Address(insideIp)));
- }
- }
-
- // Set MAC
- if (mac != null) {
- endpointL3Builder.setMacAddress(new MacAddress(mac));
- }
-
- // Set L2 context
- if (l2 != null) {
- endpointL3Builder.setL2Context(new L2BridgeDomainId(l2));
- }
-
- return endpointL3Builder.build();
-
- }
-
- protected IndexedTenant tenantCreator() {
- TenantBuilder tenantBuilder = new TenantBuilder();
- tenantBuilder.setId(new TenantId(TENANT_ID));
-
- // Set forwarding context
- SegmentationBuilder segmentationBuilder = new SegmentationBuilder();
- segmentationBuilder.setSegmentationId(1);
- List<L2FloodDomain> l2FloodDomains = new ArrayList<>();
- L2FloodDomainBuilder l2FloodDomainBuilder = new L2FloodDomainBuilder();
- l2FloodDomainBuilder.setId(new L2FloodDomainId("l2id"));
- l2FloodDomainBuilder.addAugmentation(Segmentation.class, segmentationBuilder.build());
- l2FloodDomains.add(l2FloodDomainBuilder.build());
- ForwardingContextBuilder forwardingContextBuilder = new ForwardingContextBuilder();
- forwardingContextBuilder.setL2FloodDomain(l2FloodDomains);
- tenantBuilder.setForwardingContext(forwardingContextBuilder.build());
-
- return new IndexedTenant(tenantBuilder.build());
- }
-
- protected List<L2FloodDomain> l2FloodDomainsCreator() {
- SegmentationBuilder segmentationBuilder = new SegmentationBuilder();
- segmentationBuilder.setSegmentationId(1);
- List<L2FloodDomain> l2FloodDomains = new ArrayList<>();
- L2FloodDomainBuilder l2FloodDomainBuilder = new L2FloodDomainBuilder();
- l2FloodDomainBuilder.setId(new L2FloodDomainId("l2id"));
- l2FloodDomainBuilder.addAugmentation(Segmentation.class, segmentationBuilder.build());
- l2FloodDomains.add(l2FloodDomainBuilder.build());
- return l2FloodDomains;
- }
-
- protected EndpointBuilder endpointBuilder(IpAddress ip, MacAddress mac, NodeConnectorId nodeConnectorId,
- EndpointGroupId epg, L2BridgeDomainId l2) {
- EndpointBuilder endpointBuilder = new EndpointBuilder();
-
- // Set tenant
- endpointBuilder.setTenant(new TenantId(TENANT_ID));
-
- // Set L3 address
- if (ip != null) {
- List<L3Address> l3Addresses = new ArrayList<>();
- L3AddressBuilder l3AddressBuilder = new L3AddressBuilder();
- l3AddressBuilder.setIpAddress(ip);
- l3Addresses.add(l3AddressBuilder.build());
- endpointBuilder.setL3Address(l3Addresses);
- }
-
- // Set Mac address
- endpointBuilder.setMacAddress(new MacAddress(mac));
- endpointBuilder.setL2Context(l2);
- endpointBuilder.setEndpointGroup(epg);
-
- // Augment node connector
- OfOverlayContextBuilder ofOverlayContextBuilder = new OfOverlayContextBuilder();
- ofOverlayContextBuilder.setNodeConnectorId(new NodeConnectorId(nodeConnectorId));
- ofOverlayContextBuilder.setNodeId(nodeId);
- endpointBuilder.addAugmentation(OfOverlayContext.class, ofOverlayContextBuilder.build());
-
- // Set network containment
- endpointBuilder.setNetworkContainment(new NetworkDomainId(DOMAIN_ID));
-
- return endpointBuilder;
- }
-
- protected TenantBuilder baseTenant() {
- return new TenantBuilder().setId(tid)
- .setPolicy(new PolicyBuilder()
- .setEndpointGroup(ImmutableList.of(
- new EndpointGroupBuilder().setId(eg)
- .setNetworkDomain(sub)
- .setConsumerNamedSelector(ImmutableList.of(new ConsumerNamedSelectorBuilder()
- .setName(new SelectorName("cns1")).setContract(ImmutableList.of(cid)).build()))
- .build(),
- new EndpointGroupBuilder().setId(eg2)
- .setNetworkDomain(sub2)
- .setProviderNamedSelector(ImmutableList.of(new ProviderNamedSelectorBuilder()
- .setName(new SelectorName("pns1")).setContract(ImmutableList.of(cid)).build()))
- .build()))
- .setSubjectFeatureInstances(
- new SubjectFeatureInstancesBuilder()
- .setClassifierInstance(
- ImmutableList
- .of(new ClassifierInstanceBuilder().setName(new ClassifierName("tcp_dst_80"))
- .setClassifierDefinitionId(L4ClassifierDefinition.DEFINITION.getId())
- .setParameterValue(ImmutableList.of(
- new ParameterValueBuilder().setName(new ParameterName("destport"))
- .setIntValue(Long.valueOf(80))
- .build(),
- new ParameterValueBuilder().setName(new ParameterName("proto"))
- .setIntValue(Long.valueOf(6))
- .build()))
- .build(), new ClassifierInstanceBuilder()
- .setName(new ClassifierName("tcp_src_80"))
- .setClassifierDefinitionId(Classifier.L4_CL.getId())
- .setParameterValue(ImmutableList.of(
- new ParameterValueBuilder()
- .setName(new ParameterName("sourceport"))
- .setIntValue(Long.valueOf(80))
- .build(),
- new ParameterValueBuilder().setName(new ParameterName("proto"))
- .setIntValue(Long.valueOf(6))
- .build()))
- .build(),
- new ClassifierInstanceBuilder()
- .setName(new ClassifierName("ether_type"))
- .setClassifierDefinitionId(Classifier.ETHER_TYPE_CL.getId())
- .setParameterValue(ImmutableList.of(new ParameterValueBuilder()
- .setName(new ParameterName("ethertype"))
- .setIntValue(Long.valueOf(FlowUtils.IPv4))
- .build()))
- .build()))
- .setActionInstance(
- ImmutableList.of(new ActionInstanceBuilder().setName(new ActionName("allow"))
- .setActionDefinitionId(new AllowAction().getId())
- .build()))
- .build())
- .build())
- .setForwardingContext(
- new ForwardingContextBuilder()
- .setL3Context(ImmutableList.of(new L3ContextBuilder().setId(l3c).build()))
- .setL2BridgeDomain(
- ImmutableList.of(new L2BridgeDomainBuilder().setId(bd).setParent(l3c).build()))
- .setL2FloodDomain(ImmutableList.of(
- new L2FloodDomainBuilder()
- .setId(fd)
- .setParent(bd)
- .addAugmentation(Segmentation.class,
- new SegmentationBuilder()
- .setSegmentationId(Integer.valueOf(216))
- .build())
- .build(),
- new L2FloodDomainBuilder()
- .setId(ext_fd)
- .addAugmentation(Segmentation.class,
- new SegmentationBuilder()
- .setSegmentationId(Integer.valueOf(2016))
- .build())
- .build()))
- .setSubnet(ImmutableList.of(
- new SubnetBuilder().setId(sub2)
- .setParent(fd)
- .setIpPrefix(new IpPrefix(new Ipv4Prefix("10.0.1.0/24")))
- .setVirtualRouterIp(new IpAddress(new Ipv4Address("10.0.1.1")))
- .build(),
- new SubnetBuilder().setId(sub)
- .setParent(fd)
- .setIpPrefix(new IpPrefix(new Ipv4Prefix("10.0.0.0/24")))
- .setVirtualRouterIp(new IpAddress(new Ipv4Address("10.0.0.1")))
- .build(),
- new SubnetBuilder().setId(sub3)
- .setParent(bd)
- .setIpPrefix(new IpPrefix(new Ipv4Prefix("10.0.2.0/24")))
- .setVirtualRouterIp(new IpAddress(new Ipv4Address("10.0.2.1")))
- .build(),
- new SubnetBuilder()
- .setId(ext_sub)
- .setIpPrefix(new IpPrefix(new Ipv4Prefix("192.168.111.0/24")))
- .setParent(ext_fd)
- .build()))
- .build());
- }
-}
+package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.mapper;\r
+\r
+import com.google.common.collect.ImmutableList;\r
+import org.opendaylight.groupbasedpolicy.api.sf.L4ClassifierDefinition;\r
+import org.opendaylight.groupbasedpolicy.dto.IndexedTenant;\r
+import org.opendaylight.groupbasedpolicy.dto.PolicyInfo;\r
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfContext;\r
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;\r
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.PolicyManager;\r
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.endpoint.EndpointManager;\r
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowTable;\r
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils;\r
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.node.SwitchManager;\r
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf.AllowAction;\r
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf.Classifier;\r
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;\r
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;\r
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;\r
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;\r
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;\r
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ActionName;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ClassifierName;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ContractId;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L2BridgeDomainId;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L2FloodDomainId;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L3ContextId;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.NetworkDomainId;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ParameterName;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.SelectorName;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.SubnetId;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoint.fields.L3Address;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoint.fields.L3AddressBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3Builder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.l3endpoint.rev151217.NatAddress;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.l3endpoint.rev151217.NatAddressBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayContext;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayContextBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.Segmentation;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.SegmentationBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValueBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.TenantBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.ForwardingContextBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.PolicyBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L2FloodDomain;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L2FloodDomainBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L3ContextBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.Subnet;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.SubnetBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.EndpointGroup;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.EndpointGroupBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.SubjectFeatureInstances;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.SubjectFeatureInstancesBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.endpoint.group.ConsumerNamedSelectorBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.endpoint.group.ProviderNamedSelectorBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.subject.feature.instances.ActionInstanceBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.subject.feature.instances.ClassifierInstanceBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+public abstract class MapperUtilsTest {\r
+\r
+ protected static final String IPV4_1 = "170.0.0.1";\r
+ protected static final String IPV4_2 = "190.0.0.1";\r
+ protected static final String MAC_0 = "00:00:00:00:00:00";\r
+ protected static final String MAC_1 = "00:00:00:00:00:01";\r
+ protected static final String CONNECTOR_0 = "0";\r
+ protected static final String CONNECTOR_1 = "1";\r
+ protected static final String IP_PREFIX_32 = "/32";\r
+ protected static final String IP_PREFIX_128 = "/128";\r
+ protected static final String IPV6_1 = "2000:db80:85a3:08ba:0947:8a2e:3a70:7334";\r
+ protected static final String IPV6_2 = "0947:db80:3a70:7334:85a3:8a2e:2000:08ba";\r
+ protected static final String DHCP_IP = "255.255.255.255";\r
+ protected static final String TENANT_ID = "dummy tenant";\r
+ protected static final String NODE_ID = "dummy node";\r
+ protected static final String L2 = "L2";\r
+ protected static final String EPG_ID = "dummy epg id";\r
+ protected static final String ENDPOINT_GROUP_0 = "eg0";\r
+ protected static final String ENDPOINT_GROUP_1 = "eg1";\r
+ protected static final String ENDPOINT_GROUP_2 = "eg2";\r
+ private static final String DOMAIN_ID = "dummy id";\r
+ protected final NodeId nodeId = new NodeId(NODE_ID);\r
+ protected final NodeConnectorId nodeConnectorId = new NodeConnectorId(nodeId.getValue() + CONNECTOR_0);\r
+ protected final L2BridgeDomainId bd = new L2BridgeDomainId("c95182ba-7807-43f8-98f7-6c7c720b7639");\r
+ protected final EndpointGroupId eg = new EndpointGroupId("36dec84a-08c7-497b-80b6-a0035af72a12");\r
+ protected final EndpointGroupId eg2 = new EndpointGroupId("632e5e11-7988-4eb5-8fe6-6c182d890276");\r
+ protected final ContractId cid = new ContractId("a5874893-bcd5-46de-96af-3c8d99bedf9f");\r
+ protected final L3ContextId l3c = new L3ContextId("2cf51ee4-e996-467e-a277-2d380334a91d");\r
+ protected final L2FloodDomainId fd = new L2FloodDomainId("98e1439e-52d2-46f8-bd69-5136e6088771");\r
+ protected final L2FloodDomainId ext_fd = new L2FloodDomainId("d8024f7a-b83e-11e5-9912-ba0be0483c18");\r
+ protected final SubnetId sub = new SubnetId("4fcf8dfc-53b5-4aef-84d3-6b5586992fcb");\r
+ protected final SubnetId sub2 = new SubnetId("c285a59f-fcb8-42e6-bf29-87ea522fd626");\r
+ protected final SubnetId sub3 = new SubnetId("a0380d52-2a25-48ef-882c-a4d4cd9e00ec");\r
+ protected final SubnetId ext_sub = new SubnetId("8da17ad9-3261-4dc9-bcff-928a2f73cce7");\r
+ protected final TenantId tid = new TenantId(TENANT_ID);\r
+ protected Short tableId;\r
+ protected OfContext ctx;\r
+ protected OfWriter ofWriter;\r
+ protected SwitchManager switchManager;\r
+ protected PolicyManager policyManager;\r
+ protected EndpointManager endpointManager;\r
+ protected PolicyInfo policyInfo;\r
+ protected FlowTable table;\r
+\r
+ protected FlowBuilder flowBuilder(FlowId flowId, short tableId, Integer priority, Match match, Instructions instructions) {\r
+ FlowBuilder flowBuilder = FlowUtils.base(tableId);\r
+ flowBuilder.setId(flowId)\r
+ .setPriority(priority)\r
+ .setMatch(match)\r
+ .setInstructions(instructions);\r
+\r
+ return flowBuilder;\r
+ }\r
+\r
+ protected EndpointL3Builder endpointL3Builder(String ip, String insideIp, String mac, String l2, boolean ipv6) {\r
+ EndpointL3Builder endpointL3Builder = new EndpointL3Builder();\r
+\r
+ // Set NAT address augmentation\r
+ if (ip != null) {\r
+ if (ipv6) {\r
+ NatAddressBuilder natAddressBuilder = new NatAddressBuilder();\r
+ natAddressBuilder.setNatAddress(new IpAddress(new Ipv6Address(ip)));\r
+ endpointL3Builder.addAugmentation(NatAddress.class, natAddressBuilder.build());\r
+ } else {\r
+ NatAddressBuilder natAddressBuilder = new NatAddressBuilder();\r
+ natAddressBuilder.setNatAddress(new IpAddress(new Ipv4Address(ip)));\r
+ endpointL3Builder.addAugmentation(NatAddress.class, natAddressBuilder.build());\r
+ }\r
+ }\r
+\r
+ // Set IP address\r
+ if (insideIp != null) {\r
+ if (ipv6) {\r
+ endpointL3Builder.setIpAddress(new IpAddress(new Ipv6Address(insideIp)));\r
+ } else {\r
+ endpointL3Builder.setIpAddress(new IpAddress(new Ipv4Address(insideIp)));\r
+ }\r
+ }\r
+\r
+ // Set MAC\r
+ if (mac != null) {\r
+ endpointL3Builder.setMacAddress(new MacAddress(mac));\r
+ }\r
+\r
+ // Set L2 context\r
+ if (l2 != null) {\r
+ endpointL3Builder.setL2Context(new L2BridgeDomainId(l2));\r
+ }\r
+\r
+ return endpointL3Builder;\r
+\r
+ }\r
+\r
+ protected IndexedTenant indexedTenantBuilder() {\r
+ TenantBuilder tenantBuilder = new TenantBuilder();\r
+ tenantBuilder.setId(new TenantId(TENANT_ID));\r
+\r
+ // Set forwarding context\r
+ SegmentationBuilder segmentationBuilder = new SegmentationBuilder();\r
+ segmentationBuilder.setSegmentationId(1);\r
+ List<L2FloodDomain> l2FloodDomains = new ArrayList<>();\r
+ L2FloodDomainBuilder l2FloodDomainBuilder = new L2FloodDomainBuilder();\r
+ l2FloodDomainBuilder.setId(new L2FloodDomainId("l2id"));\r
+ l2FloodDomainBuilder.addAugmentation(Segmentation.class, segmentationBuilder.build());\r
+ l2FloodDomains.add(l2FloodDomainBuilder.build());\r
+ ForwardingContextBuilder forwardingContextBuilder = new ForwardingContextBuilder();\r
+ forwardingContextBuilder.setL2FloodDomain(l2FloodDomains);\r
+ tenantBuilder.setForwardingContext(forwardingContextBuilder.build());\r
+\r
+ return new IndexedTenant(tenantBuilder.build());\r
+ }\r
+\r
+ protected List<L2FloodDomain> l2FloodDomains() {\r
+ SegmentationBuilder segmentationBuilder = new SegmentationBuilder();\r
+ segmentationBuilder.setSegmentationId(1);\r
+ List<L2FloodDomain> l2FloodDomains = new ArrayList<>();\r
+ L2FloodDomainBuilder l2FloodDomainBuilder = new L2FloodDomainBuilder();\r
+ l2FloodDomainBuilder.setId(new L2FloodDomainId("l2id"));\r
+ l2FloodDomainBuilder.addAugmentation(Segmentation.class, segmentationBuilder.build());\r
+ l2FloodDomains.add(l2FloodDomainBuilder.build());\r
+ return l2FloodDomains;\r
+ }\r
+\r
+ protected EndpointBuilder endpointBuilder(IpAddress ip, MacAddress mac, NodeConnectorId connector,\r
+ EndpointGroupId groupId, L2BridgeDomainId bridgeDomainId) {\r
+ EndpointBuilder endpointBuilder = new EndpointBuilder();\r
+\r
+ // Set tenant\r
+ endpointBuilder.setTenant(new TenantId(TENANT_ID));\r
+\r
+ // Set L3 address\r
+ if (ip != null) {\r
+ List<L3Address> l3Addresses = new ArrayList<>();\r
+ L3AddressBuilder l3AddressBuilder = new L3AddressBuilder();\r
+ l3AddressBuilder.setIpAddress(ip);\r
+ l3Addresses.add(l3AddressBuilder.build());\r
+ endpointBuilder.setL3Address(l3Addresses);\r
+ }\r
+\r
+ // Set Mac address\r
+ endpointBuilder.setMacAddress(new MacAddress(mac));\r
+ endpointBuilder.setL2Context(bridgeDomainId);\r
+ endpointBuilder.setEndpointGroup(groupId);\r
+\r
+ // Augment node connector\r
+ OfOverlayContextBuilder ofOverlayContextBuilder = new OfOverlayContextBuilder();\r
+ ofOverlayContextBuilder.setNodeConnectorId(new NodeConnectorId(connector));\r
+ ofOverlayContextBuilder.setNodeId(nodeId);\r
+ endpointBuilder.addAugmentation(OfOverlayContext.class, ofOverlayContextBuilder.build());\r
+\r
+ // Set network containment\r
+ endpointBuilder.setNetworkContainment(new NetworkDomainId(DOMAIN_ID));\r
+\r
+ return endpointBuilder;\r
+ }\r
+\r
+ protected List<EndpointGroup> endpointGroups() {\r
+ return ImmutableList.of(\r
+ new EndpointGroupBuilder().setId(eg)\r
+ .setNetworkDomain(sub)\r
+ .setConsumerNamedSelector(ImmutableList.of(new ConsumerNamedSelectorBuilder()\r
+ .setName(new SelectorName("cns1")).setContract(ImmutableList.of(cid)).build()))\r
+ .build(),\r
+ new EndpointGroupBuilder().setId(eg2)\r
+ .setNetworkDomain(sub2)\r
+ .setProviderNamedSelector(ImmutableList.of(new ProviderNamedSelectorBuilder()\r
+ .setName(new SelectorName("pns1")).setContract(ImmutableList.of(cid)).build()))\r
+ .build());\r
+ }\r
+\r
+ private SubjectFeatureInstances subjectFeatureInstances() {\r
+ SubjectFeatureInstancesBuilder builder = new SubjectFeatureInstancesBuilder();\r
+ return builder.setClassifierInstance(ImmutableList.of(new ClassifierInstanceBuilder()\r
+ .setName(new ClassifierName("tcp_dst_80"))\r
+ .setClassifierDefinitionId(L4ClassifierDefinition.DEFINITION.getId())\r
+ .setParameterValue(ImmutableList.of(new ParameterValueBuilder().setName(new ParameterName("destport"))\r
+ .setIntValue(80L)\r
+ .build(), new ParameterValueBuilder().setName(new ParameterName("proto"))\r
+ .setIntValue(6L)\r
+ .build()))\r
+ .build(), new ClassifierInstanceBuilder().setName(new ClassifierName("tcp_src_80"))\r
+ .setClassifierDefinitionId(Classifier.L4_CL.getId())\r
+ .setParameterValue(ImmutableList.of(new ParameterValueBuilder().setName(new ParameterName("sourceport"))\r
+ .setIntValue(80L)\r
+ .build(), new ParameterValueBuilder().setName(new ParameterName("proto"))\r
+ .setIntValue(6L)\r
+ .build()))\r
+ .build(), new ClassifierInstanceBuilder().setName(new ClassifierName("ether_type"))\r
+ .setClassifierDefinitionId(Classifier.ETHER_TYPE_CL.getId())\r
+ .setParameterValue(ImmutableList.of(new ParameterValueBuilder()\r
+ .setName(new ParameterName("ethertype"))\r
+ .setIntValue(FlowUtils.IPv4)\r
+ .build()))\r
+ .build()))\r
+ .setActionInstance(ImmutableList.of(new ActionInstanceBuilder().setName(new ActionName("allow"))\r
+ .setActionDefinitionId(new AllowAction().getId())\r
+ .build()))\r
+ .build();\r
+ }\r
+\r
+ protected TenantBuilder baseTenantBuilder() {\r
+ TenantBuilder tenantBuilder = new TenantBuilder();\r
+ tenantBuilder.setId(tid)\r
+ .setPolicy(new PolicyBuilder().setEndpointGroup(endpointGroups())\r
+ .setSubjectFeatureInstances(subjectFeatureInstances())\r
+ .build())\r
+ .setForwardingContext(new ForwardingContextBuilder()\r
+ .setL3Context(ImmutableList.of(new L3ContextBuilder().setId(l3c).build()))\r
+ .setL2FloodDomain(l2FloodDomains())\r
+ .setSubnet(subnet())\r
+ .build());\r
+ return tenantBuilder;\r
+ }\r
+\r
+ protected List<Subnet> subnet() {\r
+ return ImmutableList.of(\r
+ new SubnetBuilder().setId(sub2)\r
+ .setParent(fd)\r
+ .setIpPrefix(new IpPrefix(new Ipv4Prefix("10.0.1.0/24")))\r
+ .setVirtualRouterIp(new IpAddress(new Ipv4Address("10.0.1.1")))\r
+ .build(),\r
+ new SubnetBuilder().setId(sub)\r
+ .setParent(fd)\r
+ .setIpPrefix(new IpPrefix(new Ipv4Prefix("10.0.0.0/24")))\r
+ .setVirtualRouterIp(new IpAddress(new Ipv4Address("10.0.0.1")))\r
+ .build(),\r
+ new SubnetBuilder().setId(sub3)\r
+ .setParent(bd)\r
+ .setIpPrefix(new IpPrefix(new Ipv4Prefix("10.0.2.0/24")))\r
+ .setVirtualRouterIp(new IpAddress(new Ipv4Address("10.0.2.1")))\r
+ .build(),\r
+ new SubnetBuilder()\r
+ .setId(ext_sub)\r
+ .setIpPrefix(new IpPrefix(new Ipv4Prefix("192.168.111.0/24")))\r
+ .setParent(ext_fd)\r
+ .build());\r
+ }\r
+}\r
@Test
public void testDropFlow_noEthertype() {
- Flow testFlow = flowCreator(new FlowId(DROP_ALL), tableId, 100, null,
- FlowUtils.dropInstructions());
+ Flow testFlow = flowBuilder(new FlowId(DROP_ALL), tableId, 100, null,
+ FlowUtils.dropInstructions()).build();
flows.dropFlow(100, null, ofWriter);
verify(ofWriter, times(1)).writeFlow(nodeId, tableId, testFlow);
MatchBuilder matchBuilder = new MatchBuilder();
matchBuilder.setEthernetMatch(FlowUtils.ethernetMatch(null, null, FlowUtils.IPv4));
Match match = matchBuilder.build();
- Flow testFlow = flowCreator(FlowIdUtils.newFlowId(tableId, DROP, match), tableId, 100, match,
- FlowUtils.dropInstructions());
+ Flow testFlow = flowBuilder(FlowIdUtils.newFlowId(tableId, DROP, match), tableId, 100, match,
+ FlowUtils.dropInstructions()).build();
flows.dropFlow(100, FlowUtils.IPv4, ofWriter);
verify(ofWriter, times(1)).writeFlow(nodeId, tableId, testFlow);
MatchBuilder matchBuilder = new MatchBuilder();
matchBuilder.setEthernetMatch(FlowUtils.ethernetMatch(null, null, FlowUtils.IPv6));
Match match = matchBuilder.build();
- Flow testFlow = flowCreator(FlowIdUtils.newFlowId(tableId, DROP, match), tableId, 100, match,
- FlowUtils.dropInstructions());
+ Flow testFlow = flowBuilder(FlowIdUtils.newFlowId(tableId, DROP, match), tableId, 100, match,
+ FlowUtils.dropInstructions()).build();
flows.dropFlow(100, FlowUtils.IPv6, ofWriter);
verify(ofWriter, times(1)).writeFlow(nodeId, tableId, testFlow);
MatchBuilder matchBuilder = new MatchBuilder();
matchBuilder.setEthernetMatch(FlowUtils.ethernetMatch(null, null, FlowUtils.ARP));
Match match = matchBuilder.build();
- Flow testFlow = flowCreator(FlowIdUtils.newFlowId(tableId, DROP, match), tableId, 100, match,
- FlowUtils.dropInstructions());
+ Flow testFlow = flowBuilder(FlowIdUtils.newFlowId(tableId, DROP, match), tableId, 100, match,
+ FlowUtils.dropInstructions()).build();
flows.dropFlow(100, FlowUtils.ARP, ofWriter);
verify(ofWriter, times(1)).writeFlow(nodeId, tableId, testFlow);
@Test
public void testNatFlows_noAugmentation() {
- EndpointL3 endpointL3 = endpointL3Creator(null, IPV4_1, MAC_0, L2, false);
+ EndpointL3 endpointL3 = endpointL3Builder(null, IPV4_1, MAC_0, L2, false).build();
flows.natFlows((short) 6, endpointL3, 100, ofWriter);
verifyZeroInteractions(ofWriter);
}
@Test
public void testNatFlows_ipv4() {
- EndpointL3 endpointL3 = endpointL3Creator(IPV4_1, IPV4_2, MAC_0, L2, false);
+ EndpointL3 endpointL3 = endpointL3Builder(IPV4_1, IPV4_2, MAC_0, L2, false).build();
MatchBuilder matchBuilder = new MatchBuilder();
matchBuilder.setEthernetMatch(FlowUtils.ethernetMatch(null, null, FlowUtils.IPv4))
.setLayer3Match(new Ipv4MatchBuilder().setIpv4Source(new Ipv4Prefix(IPV4_2 + IP_PREFIX_32)).build());
instructions.add(goTo.build());
instructionsBuilder.setInstruction(instructions);
- Flow testFlow = flowCreator(new FlowId(EGRESS_NAT + new IpAddress(new Ipv4Address(IPV4_2)) + "|" +
- new IpAddress(new Ipv4Address(IPV4_1))), tableId, 90, match, instructionsBuilder.build());
+ Flow testFlow = flowBuilder(new FlowId(EGRESS_NAT + new IpAddress(new Ipv4Address(IPV4_2)) + "|" +
+ new IpAddress(new Ipv4Address(IPV4_1))), tableId, 90, match, instructionsBuilder.build()).build();
flows.natFlows((short) 6, endpointL3, 90, ofWriter);
verify(ofWriter, times(1)).writeFlow(nodeId, tableId, testFlow);
@Test
public void testNatFlows_ipv6() {
- EndpointL3 endpointL3 = endpointL3Creator(IPV6_1, IPV6_2, MAC_0, L2, true);
+ EndpointL3 endpointL3 = endpointL3Builder(IPV6_1, IPV6_2, MAC_0, L2, true).build();
MatchBuilder matchBuilder = new MatchBuilder();
matchBuilder.setEthernetMatch(FlowUtils.ethernetMatch(null, null, FlowUtils.IPv6))
.setLayer3Match(new Ipv6MatchBuilder().setIpv6Source(new Ipv6Prefix(IPV6_2 + IP_PREFIX_128)).build());
instructions.add(goTo.build());
instructionsBuilder.setInstruction(instructions);
- Flow testFlow = flowCreator(new FlowId(EGRESS_NAT + new IpAddress(new Ipv6Address(IPV6_2)) + "|" +
- new IpAddress(new Ipv6Address(IPV6_1))), tableId, 80, match, instructionsBuilder.build());
+ Flow testFlow = flowBuilder(new FlowId(EGRESS_NAT + new IpAddress(new Ipv6Address(IPV6_2)) + "|" +
+ new IpAddress(new Ipv6Address(IPV6_1))), tableId, 80, match, instructionsBuilder.build()).build();
flows.natFlows((short) 6, endpointL3, 80, ofWriter);
verify(ofWriter, times(1)).writeFlow(nodeId, tableId, testFlow);
EgressNatMapper mapper = new EgressNatMapper(ctx, tableId);
// Endpoint
- Endpoint endpoint = endpointCreator(new IpAddress(new Ipv4Address(IPV4_1)), new MacAddress(MAC_0),
- new NodeConnectorId(CONNECTOR_1));
+ Endpoint endpoint = endpointBuilder(new IpAddress(new Ipv4Address(IPV4_1)), new MacAddress(MAC_0),
+ new NodeConnectorId(CONNECTOR_1), null, null).build();
// L3 endpoints
- EndpointL3 endpointL3 = endpointL3Creator(IPV4_1, IPV4_2, MAC_0, L2, false);
+ EndpointL3 endpointL3 = endpointL3Builder(IPV4_1, IPV4_2, MAC_0, L2, false).build();
List<EndpointL3> endpointsL3 = new ArrayList<>();
endpointsL3.add(endpointL3);
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import com.google.common.collect.ImmutableList;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L2FloodDomainId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.Endpoint;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.l3endpoint.rev151217.NatAddressBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayContext;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayContextBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.Segmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.SegmentationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.ForwardingContextBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L2FloodDomain;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L2FloodDomainBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L3ContextBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
import org.powermock.api.mockito.PowerMockito;
import com.google.common.collect.ImmutableSet;
+import java.util.ArrayList;
+import java.util.List;
+
@RunWith(PowerMockRunner.class)
@PrepareForTest({PolicyManager.class})
public class ExternalMapperTest extends MapperUtilsTest {
.setTenant(tid)
.setMacAddress(mac)
.setL2Context(bd)
- .setNetworkContainment(sub)
+ .setNetworkContainment(ext_sub)
.setEndpointGroup(eg)
.build();
}
@Test
- public void consturctorTest() {
+ public void constructorTest() {
Assert.assertEquals(tableId, mapper.getTableId());
}
@Test
public void testSync() throws Exception {
- ctxMock.addTenant(baseTenant().build());
+ SegmentationBuilder segmentationBuilder = new SegmentationBuilder();
+ segmentationBuilder.setSegmentationId(1);
+ List<L2FloodDomain> l2FloodDomains = new ArrayList<>();
+ L2FloodDomainBuilder l2FloodDomainBuilder = new L2FloodDomainBuilder();
+ l2FloodDomainBuilder.setId(new L2FloodDomainId(ext_fd));
+ l2FloodDomainBuilder.addAugmentation(Segmentation.class, segmentationBuilder.build());
+ l2FloodDomains.add(l2FloodDomainBuilder.build());
+ ctxMock.addTenant(baseTenantBuilder().setForwardingContext(new ForwardingContextBuilder()
+ .setL3Context(ImmutableList.of(new L3ContextBuilder().setId(l3c).build()))
+ .setL2FloodDomain(l2FloodDomains)
+ .setSubnet(subnet()).build()).build());
endpointManagerMock.addL3Endpoint(natL3Ep);
l2Ep = new EndpointBuilder(l2Ep)
- .addAugmentation(OfOverlayContext.class,new OfOverlayContextBuilder()
- .setNodeId(nodeId)
- .build())
- .build();
+ .addAugmentation(OfOverlayContext.class, new OfOverlayContextBuilder()
+ .setNodeId(nodeId)
+ .build())
+ .build();
endpointManagerMock.addEndpoint(l2Ep);
- switchManagerMock.addSwitch(nodeId,null,ImmutableSet.of(nodeConnectorId), null);
+ switchManagerMock.addSwitch(nodeId, null, ImmutableSet.of(nodeConnectorId), null);
mapper.sync(l2Ep, ofWriter);
verify(ofWriter, times(4)).writeFlow(any(NodeId.class), any(Short.class), any(Flow.class));
}
@Test
public void testSync_NoExternalPorts() throws Exception {
// we still need ExternalMapper flows (default output and default drop) to be generated
- ctxMock.addTenant(baseTenant().build());
+ ctxMock.addTenant(baseTenantBuilder().build());
mapper.sync(l2Ep, ofWriter);
verify(ofWriter, times(2)).writeFlow(any(NodeId.class), any(Short.class), any(Flow.class));
}
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.*;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.*;
-import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.outputAction;
public class IngressNatMapperFlowsTest extends MapperUtilsTest {
policyInfo = mock(PolicyInfo.class);
tableId = 1;
flows = new IngressNatMapperFlows(nodeId, tableId);
+ OrdinalFactory.resetPolicyOrdinalValue();
}
@Test
public void testBaseFlow() {
- Flow testFlow = flowCreator(FlowIdUtils.newFlowId(GOTO_DESTINATION_MAPPER), tableId, 50, null,
- FlowUtils.gotoTableInstructions((short) 2));
+ Flow testFlow = flowBuilder(FlowIdUtils.newFlowId(GOTO_DESTINATION_MAPPER), tableId, 50, null,
+ FlowUtils.gotoTableInstructions((short) 2)).build();
flows.baseFlow((short) 2, 50, ofWriter);
verify(ofWriter, times(1)).writeFlow(nodeId, tableId, testFlow);
@Test
public void testNatFlow_noAugmentation() {
- EndpointL3 testEndpointL3 = endpointL3Creator(null, null, null, null, false);
+ EndpointL3 testEndpointL3 = endpointL3Builder(null, null, null, null, false).build();
flows.createNatFlow((short) 3, testEndpointL3, null, 60, ofWriter);
verifyZeroInteractions(ctx);
@Test
public void testNatFlow() throws Exception {
- EndpointL3 testEndpointL3 = endpointL3Creator(IPV4_1, IPV4_2, null, null, false);
- Endpoint testEndpoint = endpointCreator(null, new MacAddress(MAC_0),
- new NodeConnectorId(CONNECTOR_0));
+ EndpointL3 testEndpointL3 = endpointL3Builder(IPV4_1, IPV4_2, null, null, false).build();
+ Endpoint testEndpoint = endpointBuilder(null, new MacAddress(MAC_0),
+ new NodeConnectorId(CONNECTOR_0), null, null).build();
when(ctx.getEndpointManager()).thenReturn(endpointManager);
- when(ctx.getTenant(Mockito.any(TenantId.class))).thenReturn(tenantCreator());
+ when(ctx.getTenant(Mockito.any(TenantId.class))).thenReturn(indexedTenantBuilder());
when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
OrdinalFactory.EndpointFwdCtxOrdinals ordinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, testEndpoint);
IP_PREFIX_32)).build());
matchBuilder.setEthernetMatch(FlowUtils.ethernetMatch(null, null, FlowUtils.IPv4));
- Flow testFlow = flowCreator(new FlowId(INGRESS_NAT + "|" + new IpAddress(new Ipv4Address(IPV4_1)).toString() +
+ Flow testFlow = flowBuilder(new FlowId(INGRESS_NAT + "|" + new IpAddress(new Ipv4Address(IPV4_1)).toString() +
"|" + new IpAddress(new Ipv4Address(IPV4_2)).toString() + "|" + "null"), tableId, 60, matchBuilder.build(),
- instructionsBuilder.build());
+ instructionsBuilder.build()).build();
flows.createNatFlow((short) 2, testEndpointL3, ordinals, 60, ofWriter);
verify(ofWriter, times(1)).writeFlow(nodeId, tableId, testFlow);
@Test
public void testArpFlow_noAugmentation() {
- EndpointL3 testEndpointL3 = endpointL3Creator(null, null, null, null, false);
+ EndpointL3 testEndpointL3 = endpointL3Builder(null, null, null, null, false).build();
- flows.createArpFlow(tenantCreator(), testEndpointL3, 60, ofWriter);
+ flows.createArpFlow(indexedTenantBuilder(), testEndpointL3, 60, ofWriter);
verifyZeroInteractions(ctx);
verifyZeroInteractions(ofWriter);
}
@Test
public void testArpFlow() {
- EndpointL3 testEndpointL3 = endpointL3Creator(IPV4_1, IPV4_2, MAC_0, null, false);
+ EndpointL3 testEndpointL3 = endpointL3Builder(IPV4_1, IPV4_2, MAC_0, null, false).build();
List<Instruction> instructions = new ArrayList<>();
Action[] arpActions = {nxMoveEthSrcToEthDstAction(), setDlSrcAction(new MacAddress(MAC_0)),
nxLoadArpOpAction(BigInteger.valueOf(2L)), nxMoveArpShaToArpThaAction(), nxLoadArpShaAction(new BigInteger("0")),
+ IP_PREFIX_32)).build());
Match match = matchBuilder.build();
- Flow testFlow = flowCreator(FlowIdUtils.newFlowId(tableId, INGRESS_ARP, match),
- tableId, 60, match, instructionsBuilder.build());
+ Flow testFlow = flowBuilder(FlowIdUtils.newFlowId(tableId, INGRESS_ARP, match),
+ tableId, 60, match, instructionsBuilder.build()).build();
- flows.createArpFlow(tenantCreator(), testEndpointL3, 60, ofWriter);
+ flows.createArpFlow(indexedTenantBuilder(), testEndpointL3, 60, ofWriter);
verify(ofWriter, times(1)).writeFlow(nodeId, tableId, testFlow);
}
@Test
public void testIngressExternalNatFlow() throws Exception {
- Endpoint testEndpoint = endpointCreator(new IpAddress(new Ipv6Address(IPV6_1)), new MacAddress(MAC_0),
- new NodeConnectorId(CONNECTOR_0));
+ Endpoint testEndpoint = endpointBuilder(new IpAddress(new Ipv6Address(IPV6_1)), new MacAddress(MAC_0),
+ new NodeConnectorId(CONNECTOR_0), null, null).build();
when(ctx.getEndpointManager()).thenReturn(endpointManager);
- when(ctx.getTenant(Mockito.any(TenantId.class))).thenReturn(tenantCreator());
+ when(ctx.getTenant(Mockito.any(TenantId.class))).thenReturn(indexedTenantBuilder());
when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
OrdinalFactory.EndpointFwdCtxOrdinals ordinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, testEndpoint);
matchBuilder.setLayer3Match(new Ipv6MatchBuilder().setIpv6Source(new Ipv6Prefix(IPV6_1 + IP_PREFIX_128)).build());
Match match = matchBuilder.build();
- Flow testFlow = flowCreator(FlowIdUtils.newFlowId(tableId, INBOUND_EXTERNAL_IP, match), tableId, 50, match,
- instructionsBuilder.build());
+ Flow testFlow = flowBuilder(FlowIdUtils.newFlowId(tableId, INBOUND_EXTERNAL_IP, match), tableId, 50, match,
+ instructionsBuilder.build()).build();
flows.createIngressExternalNatFlows((short) 2, testEndpoint, ordinals, 50, ofWriter);
verify(ofWriter, times(1)).writeFlow(nodeId, tableId, testFlow);
@Test
public void testIngressExternalArpFlow() throws Exception {
- Endpoint testEndpoint = endpointCreator(new IpAddress(new Ipv4Address(IPV4_1)), new MacAddress(MAC_0),
- new NodeConnectorId(CONNECTOR_0));
+ Endpoint testEndpoint = endpointBuilder(new IpAddress(new Ipv4Address(IPV4_1)), new MacAddress(MAC_0),
+ new NodeConnectorId(CONNECTOR_0), null, null).build();
when(ctx.getEndpointManager()).thenReturn(endpointManager);
- when(ctx.getTenant(Mockito.any(TenantId.class))).thenReturn(tenantCreator());
+ when(ctx.getTenant(Mockito.any(TenantId.class))).thenReturn(indexedTenantBuilder());
when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
OrdinalFactory.EndpointFwdCtxOrdinals ordinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, testEndpoint);
matchBuilder.setEthernetMatch(FlowUtils.ethernetMatch(new MacAddress(MAC_0), null, FlowUtils.ARP));
Match match = matchBuilder.build();
- Flow testFlow = flowCreator(FlowIdUtils.newFlowId(tableId, INBOUND_EXTERNAL_ARP, match), tableId, 30, match,
- instructionsBuilder.build());
+ Flow testFlow = flowBuilder(FlowIdUtils.newFlowId(tableId, INBOUND_EXTERNAL_ARP, match), tableId, 30, match,
+ instructionsBuilder.build()).build();
flows.createIngressExternalArpFlows((short) 0, testEndpoint, ordinals, 30, ofWriter);
verify(ofWriter, times(1)).writeFlow(nodeId, tableId, testFlow);
public void testSyncFlows() throws Exception {
// Endpoints
- Endpoint endpoint = endpointCreator(new IpAddress(new Ipv4Address(IPV4_1)), new MacAddress(MAC_0),
- new NodeConnectorId(CONNECTOR_0));
+ Endpoint endpoint = endpointBuilder(new IpAddress(new Ipv4Address(IPV4_1)), new MacAddress(MAC_0),
+ new NodeConnectorId(CONNECTOR_0), null, null).build();
List<Endpoint> endpoints = new ArrayList<>();
endpoints.add(endpoint);
// L3 endpoints
- EndpointL3 endpointL3 = endpointL3Creator(IPV4_1, IPV4_2, MAC_0, L2, false);
+ EndpointL3 endpointL3 = endpointL3Builder(IPV4_1, IPV4_2, MAC_0, L2, false).build();
List<EndpointL3> endpointsL3 = new ArrayList<>();
endpointsL3.add(endpointL3);
egKeys.add(new EgKey(new TenantId(TENANT_ID), new EndpointGroupId(EPG_ID)));
when(ctx.getPolicyManager()).thenReturn(policyManager);
- when(ctx.getTenant(Mockito.any(TenantId.class))).thenReturn(tenantCreator());
+ when(ctx.getTenant(Mockito.any(TenantId.class))).thenReturn(indexedTenantBuilder());
when(ctx.getEndpointManager()).thenReturn(endpointManager);
when(endpointManager.getL3EndpointsWithNat()).thenReturn(endpointsL3);
when(endpointManager.getEndpoint(Mockito.any(EpKey.class))).thenReturn(endpoint);
Endpoint ep2 = endpointBuilder(new IpAddress(IPV4_2.toCharArray()), new MacAddress(MAC_1), nodeConnectorId, eg, bd)
.build();
endpointManagerMock.addEndpoint(ep2);
- ctxMock.addTenant(baseTenant().setPolicy(new PolicyBuilder(baseTenant().getPolicy())
+ ctxMock.addTenant(baseTenantBuilder().setPolicy(new PolicyBuilder(baseTenantBuilder().getPolicy())
.setContract(ImmutableList.of(baseContract(null).build())).build()).build());
ofWriter = new OfWriter();
Endpoint ep2 = endpointBuilder(new IpAddress(IPV4_2.toCharArray()), new MacAddress(MAC_1), nodeConnectorId, eg2, bd)
.build();
endpointManagerMock.addEndpoint(ep2);
- ctxMock.addTenant(baseTenant().setPolicy(new PolicyBuilder(baseTenant().getPolicy())
+ ctxMock.addTenant(baseTenantBuilder().setPolicy(new PolicyBuilder(baseTenantBuilder().getPolicy())
.setContract(ImmutableList.of(baseContract(subjects).build())).build()).build());
ofWriter = new OfWriter();
.build();
endpointManagerMock.addEndpoint(ep2);
- TenantBuilder tb = baseTenant().setPolicy(new PolicyBuilder(baseTenant().getPolicy()).setContract(
+ TenantBuilder tb = baseTenantBuilder().setPolicy(new PolicyBuilder(baseTenantBuilder().getPolicy()).setContract(
ImmutableList.of(new ContractBuilder().setId(cid)
.setSubject(ImmutableList.of(baseSubject(Direction.Out).build()))
.setClause(
@Test
public void testDropFlow_noEthertype() {
- Flow testFlow = flowCreator(new FlowId(DROP_ALL), tableId, 100, null, FlowUtils.dropInstructions());
+ Flow testFlow = flowBuilder(new FlowId(DROP_ALL), tableId, 100, null, FlowUtils.dropInstructions()).build();
flows.dropFlow(100, null, ofWriter);
verify(ofWriter, times(1)).writeFlow(nodeId, tableId, testFlow);
MatchBuilder matchBuilder = new MatchBuilder();
matchBuilder.setEthernetMatch(FlowUtils.ethernetMatch(null, null, FlowUtils.IPv4));
Match match = matchBuilder.build();
- Flow testFlow = flowCreator(FlowIdUtils.newFlowId(tableId, DROP, match), tableId, 100, match,
- FlowUtils.dropInstructions());
+ Flow testFlow = flowBuilder(FlowIdUtils.newFlowId(tableId, DROP, match), tableId, 100, match,
+ FlowUtils.dropInstructions()).build();
flows.dropFlow(100, FlowUtils.IPv4, ofWriter);
verify(ofWriter, times(1)).writeFlow(nodeId, tableId, testFlow);
MatchBuilder matchBuilder = new MatchBuilder();
matchBuilder.setEthernetMatch(FlowUtils.ethernetMatch(null, null, FlowUtils.IPv6));
Match match = matchBuilder.build();
- Flow testFlow = flowCreator(FlowIdUtils.newFlowId(tableId, DROP, match), tableId, 100, match,
- FlowUtils.dropInstructions());
+ Flow testFlow = flowBuilder(FlowIdUtils.newFlowId(tableId, DROP, match), tableId, 100, match,
+ FlowUtils.dropInstructions()).build();
flows.dropFlow(100, FlowUtils.IPv6, ofWriter);
verify(ofWriter, times(1)).writeFlow(nodeId, tableId, testFlow);
MatchBuilder matchBuilder = new MatchBuilder();
matchBuilder.setEthernetMatch(FlowUtils.ethernetMatch(null, null, FlowUtils.ARP));
Match match = matchBuilder.build();
- Flow testFlow = flowCreator(FlowIdUtils.newFlowId(tableId, DROP, match), tableId, 100, match,
- FlowUtils.dropInstructions());
+ Flow testFlow = flowBuilder(FlowIdUtils.newFlowId(tableId, DROP, match), tableId, 100, match,
+ FlowUtils.dropInstructions()).build();
flows.dropFlow(100, FlowUtils.ARP, ofWriter);
verify(ofWriter, times(1)).writeFlow(nodeId, tableId, testFlow);
MatchBuilder matchBuilder = new MatchBuilder();
matchBuilder.setInPort(new NodeConnectorId(String.valueOf(VXLAN_PORT)));
Match match = matchBuilder.build();
- Flow testFlow = flowCreator(FlowIdUtils.newFlowId(tableId, ALLOW, match), tableId, 300, match,
- FlowUtils.gotoTableInstructions((short) 2));
+ Flow testFlow = flowBuilder(FlowIdUtils.newFlowId(tableId, ALLOW, match), tableId, 300, match,
+ FlowUtils.gotoTableInstructions((short) 2)).build();
flows.allowFromTunnelFlow((short) 2, 300, new NodeConnectorId(CONNECTOR_0), ofWriter);
verify(ofWriter, times(1)).writeFlow(nodeId, tableId, testFlow);
MatchBuilder matchBuilder = new MatchBuilder();
matchBuilder.setInPort(new NodeConnectorId(String.valueOf(VXLAN_PORT)));
Match match = matchBuilder.build();
- Flow testFlow = flowCreator(FlowIdUtils.newFlowId(tableId, ALLOW, match), tableId, 300, match,
- FlowUtils.gotoTableInstructions((short) 2));
+ Flow testFlow = flowBuilder(FlowIdUtils.newFlowId(tableId, ALLOW, match), tableId, 300, match,
+ FlowUtils.gotoTableInstructions((short) 2)).build();
flows.allowFromTunnelFlow((short) 2, 300, new NodeConnectorId(CONNECTOR_1), ofWriter);
verify(ofWriter, times(1)).writeFlow(nodeId, tableId, testFlow);
IpAddress ipAddress = new IpAddress(new Ipv4Address(IPV4_1));
MacAddress macAddress = new MacAddress(MAC_0);
NodeConnectorId connectorId = new NodeConnectorId(CONNECTOR_0);
- Endpoint testEp = endpointCreator(ipAddress, macAddress, connectorId);
+ Endpoint testEp = endpointBuilder(ipAddress, macAddress, connectorId, null, null).build();
MatchBuilder matchBuilder = new MatchBuilder();
matchBuilder.setEthernetMatch(FlowUtils.ethernetMatch(macAddress, null, FlowUtils.IPv4))
.setInPort(connectorId);
Match match = matchBuilder.build();
- Flow testFlow = flowCreator(FlowIdUtils.newFlowId(tableId, L3, match), tableId, 100, match,
- FlowUtils.gotoTableInstructions((short) 2));
+ Flow testFlow = flowBuilder(FlowIdUtils.newFlowId(tableId, L3, match), tableId, 100, match,
+ FlowUtils.gotoTableInstructions((short) 2)).build();
flows.l3Flow((short) 2, testEp, new NodeConnectorId(CONNECTOR_0), new MacAddress(MAC_0), 100, false, ofWriter);
verify(ofWriter, times(1)).writeFlow(nodeId, tableId, testFlow);
IpAddress ipAddress = new IpAddress(new Ipv4Address(IPV4_1));
MacAddress macAddress = new MacAddress(MAC_1);
NodeConnectorId connectorId = new NodeConnectorId(CONNECTOR_1);
- Endpoint testEp = endpointCreator(ipAddress, macAddress, connectorId);
+ Endpoint testEp = endpointBuilder(ipAddress, macAddress, connectorId, null, null).build();
MatchBuilder matchBuilder = new MatchBuilder();
matchBuilder.setEthernetMatch(FlowUtils.ethernetMatch(macAddress, null, FlowUtils.ARP))
.setInPort(connectorId);
Match match = matchBuilder.build();
- Flow testFlow = flowCreator(FlowIdUtils.newFlowId(tableId, L3, match), tableId, 100, match,
- FlowUtils.gotoTableInstructions((short) 2));
+ Flow testFlow = flowBuilder(FlowIdUtils.newFlowId(tableId, L3, match), tableId, 100, match,
+ FlowUtils.gotoTableInstructions((short) 2)).build();
flows.l3Flow((short) 2, testEp, new NodeConnectorId(CONNECTOR_1), new MacAddress(MAC_1), 100, true, ofWriter);
verify(ofWriter, times(1)).writeFlow(nodeId, tableId, testFlow);
IpAddress ipAddress = new IpAddress(new Ipv6Address(IPV6_1));
MacAddress macAddress = new MacAddress(MAC_0);
NodeConnectorId connectorId = new NodeConnectorId(CONNECTOR_0);
- Endpoint testEp = endpointCreator(ipAddress, macAddress, connectorId);
+ Endpoint testEp = endpointBuilder(ipAddress, macAddress, connectorId, null, null).build();
MatchBuilder matchBuilder = new MatchBuilder();
matchBuilder.setEthernetMatch(FlowUtils.ethernetMatch(macAddress, null, FlowUtils.IPv6))
.setInPort(connectorId);
Match match = matchBuilder.build();
- Flow testFlow = flowCreator(FlowIdUtils.newFlowId(tableId, L3, match), tableId, 100, match,
- FlowUtils.gotoTableInstructions((short) 2));
+ Flow testFlow = flowBuilder(FlowIdUtils.newFlowId(tableId, L3, match), tableId, 100, match,
+ FlowUtils.gotoTableInstructions((short) 2)).build();
flows.l3Flow((short) 2, testEp, new NodeConnectorId(CONNECTOR_0), new MacAddress(MAC_0), 100, false, ofWriter);
verify(ofWriter, times(1)).writeFlow(nodeId, tableId, testFlow);
IpAddress ipAddress = new IpAddress(new Ipv6Address(IPV6_1));
MacAddress macAddress = new MacAddress(MAC_1);
NodeConnectorId connectorId = new NodeConnectorId(CONNECTOR_1);
- Endpoint testEp = endpointCreator(ipAddress, macAddress, connectorId);
+ Endpoint testEp = endpointBuilder(ipAddress, macAddress, connectorId, null, null).build();
flows.l3Flow((short) 2, testEp, new NodeConnectorId(CONNECTOR_1), new MacAddress(MAC_1), 100, true, ofWriter);
verifyZeroInteractions(ofWriter);
.setInPort(connectorId);
Match match = matchBuilder.build();
- Flow testFlow = flowCreator(FlowIdUtils.newFlowId(tableId, DHCP, match), tableId, 50, match,
- FlowUtils.gotoTableInstructions((short) 2));
+ Flow testFlow = flowBuilder(FlowIdUtils.newFlowId(tableId, DHCP, match), tableId, 50, match,
+ FlowUtils.gotoTableInstructions((short) 2)).build();
flows.l3DhcpDoraFlow((short) 2, new NodeConnectorId(CONNECTOR_1), new MacAddress(MAC_1), 50, ofWriter);
verify(ofWriter, times(1)).writeFlow(nodeId, tableId, testFlow);
.setInPort(connectorId);
Match match = matchBuilder.build();
- Flow testFlow = flowCreator(FlowIdUtils.newFlowId(tableId, L2, match), tableId, 100, match,
- FlowUtils.gotoTableInstructions((short) 2));
+ Flow testFlow = flowBuilder(FlowIdUtils.newFlowId(tableId, L2, match), tableId, 100, match,
+ FlowUtils.gotoTableInstructions((short) 2)).build();
flows.l2flow((short) 2, new NodeConnectorId(CONNECTOR_0), new MacAddress(MAC_0), 100, ofWriter);
verify(ofWriter, times(1)).writeFlow(nodeId, tableId, testFlow);
InstructionsBuilder instructionsBuilder = new InstructionsBuilder();
instructionsBuilder.setInstruction(instructions);
- List<L2FloodDomain> l2FloodDomains = l2FloodDomainsCreator();
+ List<L2FloodDomain> l2FloodDomains = l2FloodDomains();
- Flow testFlow = flowCreator(FlowIdUtils.newFlowId(tableId, ALLOW_EXTERNAL_POP_VLAN, match), tableId, 200, match,
- instructionsBuilder.build());
+ Flow testFlow = flowBuilder(FlowIdUtils.newFlowId(tableId, ALLOW_EXTERNAL_POP_VLAN, match), tableId, 200, match,
+ instructionsBuilder.build()).build();
flows.popVlanTagsOnExternalPortFlows((short) 0, connectorId, l2FloodDomains, 200, ofWriter);
verify(ofWriter, times(1)).writeFlow(nodeId, tableId, testFlow);
matchBuilder.setInPort(connectorId);
Match match = matchBuilder.build();
- Flow testFlow = flowCreator(FlowIdUtils.newFlowId(tableId, ALLOW_EXTERNAL, match), tableId, 250, match,
- FlowUtils.gotoTableInstructions((short) 2));
+ Flow testFlow = flowBuilder(FlowIdUtils.newFlowId(tableId, ALLOW_EXTERNAL, match), tableId, 250, match,
+ FlowUtils.gotoTableInstructions((short) 2)).build();
flows.allowFromExternalPortFlow((short) 2, connectorId, 250, ofWriter);
verify(ofWriter, times(1)).writeFlow(nodeId, tableId, testFlow);
}
connectors.add(new NodeConnectorId(CONNECTOR_0));
// Prepare endpoint
- EndpointBuilder endpointBuilder = new EndpointBuilder(endpointCreator(ipAddress, macAddress, connectorId));
- endpointBuilder.setTenant(tenantCreator().getTenant().getId());
+ EndpointBuilder endpointBuilder = new EndpointBuilder(endpointBuilder(ipAddress, macAddress, connectorId,
+ null, null).build());
+ endpointBuilder.setTenant(indexedTenantBuilder().getTenant().getId());
Endpoint endpoint = endpointBuilder.build();
when(ctx.getEndpointManager()).thenReturn(endpointManager);
when(ctx.getSwitchManager()).thenReturn(switchManager);
when(ctx.getPolicyManager()).thenReturn(policyManager);
- when(ctx.getTenant(Mockito.any(TenantId.class))).thenReturn(tenantCreator());
+ when(ctx.getTenant(Mockito.any(TenantId.class))).thenReturn(indexedTenantBuilder());
when(endpointManager.getEndpointNodeConnectorId(Mockito.any(Endpoint.class)))
.thenReturn(new NodeConnectorId(CONNECTOR_0));
when(switchManager.getTunnelPort(nodeId, TunnelTypeVxlan.class)).thenReturn(new NodeConnectorId(CONNECTOR_0));
verify(flows, times(1)).l2flow(Mockito.anyShort(), Mockito.any(NodeConnectorId.class),
Mockito.any(MacAddress.class), Mockito.anyInt(), eq(ofWriter));
verify(flows, times(1)).popVlanTagsOnExternalPortFlows(Mockito.anyShort(), Mockito.any(NodeConnectorId.class),
- eq(l2FloodDomainsCreator()), Mockito.anyInt(), eq(ofWriter));
+ eq(l2FloodDomains()), Mockito.anyInt(), eq(ofWriter));
verify(flows, times(1)).allowFromExternalPortFlow(Mockito.anyShort(), Mockito.any(NodeConnectorId.class),
Mockito.anyInt(), eq(ofWriter));
order.verify(ctx, times(1)).getSwitchManager();
order.verify(ctx, times(2)).getTenant(Mockito.any(TenantId.class));
order.verify(flows, times(1)).popVlanTagsOnExternalPortFlows(Mockito.anyShort(), Mockito.any(NodeConnectorId.class),
- eq(l2FloodDomainsCreator()), Mockito.anyInt(), eq(ofWriter));
+ eq(l2FloodDomains()), Mockito.anyInt(), eq(ofWriter));
order.verify(flows, times(1)).allowFromExternalPortFlow(Mockito.anyShort(), Mockito.any(NodeConnectorId.class),
Mockito.anyInt(), eq(ofWriter));
}
--- /dev/null
+package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.mapper.source;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InOrder;
+import org.mockito.Mockito;
+import org.opendaylight.groupbasedpolicy.dto.PolicyInfo;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfContext;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.endpoint.EndpointManager;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowIdUtils;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.OrdinalFactory;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.mapper.MapperUtilsTest;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action;
+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.Flow;
+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.Match;
+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.list.Instruction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.Endpoint;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg0;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg4;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg5;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg6;
+
+import java.lang.reflect.Field;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.*;
+
+
+public class SourceMapperFlowsTest extends MapperUtilsTest {
+
+ private static final String DROP = "drop";
+ private static final String DROP_ALL = "dropAll";
+ private static final String TUNNEL = "tunnel";
+ private static final String FLOOD_ID = "tunnelFdId";
+
+ private SourceMapperFlows flows;
+
+ @Before
+ public void init() {
+ tableId = 2;
+ ctx = mock(OfContext.class);
+ endpointManager = mock(EndpointManager.class);
+ policyInfo = mock(PolicyInfo.class);
+ ofWriter = mock(OfWriter.class);
+ flows = new SourceMapperFlows(nodeId, tableId);
+ OrdinalFactory.resetPolicyOrdinalValue();
+ }
+
+ @Test
+ public void dropFlow_noEthertype() {
+ Flow testFlow = flowBuilder(new FlowId(DROP_ALL), tableId, 100, null, FlowUtils.dropInstructions()).build();
+
+ flows.dropFlow(100, null, ofWriter);
+ verify(ofWriter, times(1)).writeFlow(nodeId, tableId, testFlow);
+ }
+
+ @Test
+ public void dropFlow_ipV4Ethertype() {
+ MatchBuilder matchBuilder = new MatchBuilder();
+ matchBuilder.setEthernetMatch(FlowUtils.ethernetMatch(null, null, FlowUtils.IPv4));
+ Match match = matchBuilder.build();
+ Flow testFlow = flowBuilder(FlowIdUtils.newFlowId(tableId, DROP, match), tableId, 100, match,
+ FlowUtils.dropInstructions()).build();
+
+ flows.dropFlow(100, FlowUtils.IPv4, ofWriter);
+ verify(ofWriter, times(1)).writeFlow(nodeId, tableId, testFlow);
+ }
+
+ @Test
+ public void dropFlow_ipV6Ethertype() {
+ MatchBuilder matchBuilder = new MatchBuilder();
+ matchBuilder.setEthernetMatch(FlowUtils.ethernetMatch(null, null, FlowUtils.IPv6));
+ Match match = matchBuilder.build();
+ Flow testFlow = flowBuilder(FlowIdUtils.newFlowId(tableId, DROP, match), tableId, 100, match,
+ FlowUtils.dropInstructions()).build();
+
+ flows.dropFlow(100, FlowUtils.IPv6, ofWriter);
+ verify(ofWriter, times(1)).writeFlow(nodeId, tableId, testFlow);
+ }
+
+ @Test
+ public void dropFlow_arpEthertype() {
+ MatchBuilder matchBuilder = new MatchBuilder();
+ matchBuilder.setEthernetMatch(FlowUtils.ethernetMatch(null, null, FlowUtils.ARP));
+ Match match = matchBuilder.build();
+ Flow testFlow = flowBuilder(FlowIdUtils.newFlowId(tableId, DROP, match), tableId, 100, match,
+ FlowUtils.dropInstructions()).build();
+
+ flows.dropFlow(100, FlowUtils.ARP, ofWriter);
+ verify(ofWriter, times(1)).writeFlow(nodeId, tableId, testFlow);
+ }
+
+ @Test
+ public void synchronizeEp() throws Exception {
+ Endpoint testEndpoint = endpointBuilder(new IpAddress(new Ipv4Address(IPV4_1)), new MacAddress(MAC_1),
+ new NodeConnectorId(CONNECTOR_1), null, null).build();
+
+ when(ctx.getEndpointManager()).thenReturn(endpointManager);
+ when(ctx.getTenant(Mockito.any(TenantId.class))).thenReturn(indexedTenantBuilder());
+ when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
+
+ OrdinalFactory.EndpointFwdCtxOrdinals ordinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, testEndpoint);
+
+ InOrder order = inOrder(ctx);
+ order.verify(ctx, times(1)).getEndpointManager();
+ order.verify(ctx, times(1)).getCurrentPolicy();
+ verify(ctx, times(2)).getTenant(new TenantId(TENANT_ID));
+ assertNotNull(ordinals);
+
+ Action reg0 = FlowUtils.nxLoadRegAction(NxmNxReg0.class, BigInteger.valueOf(1));
+ Action reg1 = FlowUtils.nxLoadRegAction(NxmNxReg1.class, BigInteger.valueOf(0));
+ Action reg4 = FlowUtils.nxLoadRegAction(NxmNxReg4.class, BigInteger.valueOf(0));
+ Action reg5 = FlowUtils.nxLoadRegAction(NxmNxReg5.class, BigInteger.valueOf(0));
+ Action reg6 = FlowUtils.nxLoadRegAction(NxmNxReg6.class, BigInteger.valueOf(0));
+ Action tunnelId = FlowUtils.nxLoadTunIdAction(BigInteger.valueOf(2), false);
+ InstructionsBuilder instructionsBuilder = new InstructionsBuilder();
+ List<Instruction> instructions = new ArrayList<>();
+ InstructionBuilder ordinalsInstruction = new InstructionBuilder();
+ ordinalsInstruction.setInstruction(FlowUtils.applyActionIns(reg0, reg1, reg4, reg5, reg6,
+ tunnelId)).setOrder(0);
+ InstructionBuilder goToInstruction = new InstructionBuilder();
+ goToInstruction.setInstruction(FlowUtils.gotoTableIns((short) 3)).setOrder(1);
+ instructions.add(ordinalsInstruction.build());
+ instructions.add(goToInstruction.build());
+ instructionsBuilder.setInstruction(instructions);
+
+ MatchBuilder matchBuilder = new MatchBuilder();
+ matchBuilder.setEthernetMatch(FlowUtils.ethernetMatch(new MacAddress(MAC_1), null, null))
+ .setInPort(new NodeConnectorId(CONNECTOR_1));
+ Match match = matchBuilder.build();
+
+ Flow testFlow = flowBuilder(FlowIdUtils.newFlowId(tableId, "ep", match), tableId, 90, match,
+ instructionsBuilder.build()).build();
+
+ flows.synchronizeEp((short) 3, 90, ordinals, new MacAddress(MAC_1), new NodeConnectorId(CONNECTOR_1), ofWriter);
+ verify(ofWriter, times(1)).writeFlow(nodeId, tableId, testFlow);
+ }
+
+ @Test
+ public void createTunnelFlow() throws Exception {
+ Endpoint testEndpoint = endpointBuilder(new IpAddress(new Ipv4Address(IPV4_1)), new MacAddress(MAC_0),
+ new NodeConnectorId(CONNECTOR_0), null, null).build();
+
+ when(ctx.getEndpointManager()).thenReturn(endpointManager);
+ when(ctx.getTenant(Mockito.any(TenantId.class))).thenReturn(indexedTenantBuilder());
+ when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
+
+ OrdinalFactory.EndpointFwdCtxOrdinals ordinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, testEndpoint);
+
+ InOrder order = inOrder(ctx);
+ order.verify(ctx, times(1)).getEndpointManager();
+ order.verify(ctx, times(1)).getCurrentPolicy();
+ verify(ctx, times(2)).getTenant(new TenantId(TENANT_ID));
+ assertNotNull(ordinals);
+
+ Action reg0 = FlowUtils.nxLoadRegAction(NxmNxReg0.class, BigInteger.valueOf(1));
+ Action reg1 = FlowUtils.nxLoadRegAction(NxmNxReg1.class, BigInteger.valueOf(0xffffff));
+ Action reg4 = FlowUtils.nxLoadRegAction(NxmNxReg4.class, BigInteger.valueOf(0));
+ Action reg5 = FlowUtils.nxLoadRegAction(NxmNxReg5.class, BigInteger.valueOf(0));
+ Action reg6 = FlowUtils.nxLoadRegAction(NxmNxReg6.class, BigInteger.valueOf(0));
+ InstructionsBuilder instructionsBuilder = new InstructionsBuilder();
+ List<Instruction> instructions = new ArrayList<>();
+ InstructionBuilder ordinalsInstruction = new InstructionBuilder();
+ ordinalsInstruction.setInstruction(FlowUtils.applyActionIns(reg0, reg1, reg4, reg5, reg6)).setOrder(0);
+ InstructionBuilder goToInstruction = new InstructionBuilder();
+ goToInstruction.setInstruction(FlowUtils.gotoTableIns((short) 3)).setOrder(1);
+ instructions.add(ordinalsInstruction.build());
+ instructions.add(goToInstruction.build());
+ instructionsBuilder.setInstruction(instructions);
+
+ MatchBuilder matchBuilder = new MatchBuilder();
+ matchBuilder.setInPort(new NodeConnectorId(CONNECTOR_0));
+ FlowUtils.addNxTunIdMatch(matchBuilder, 2);
+ Match match = matchBuilder.build();
+
+ Flow testFlow = flowBuilder(FlowIdUtils.newFlowId(tableId, TUNNEL, match), tableId, 80, match,
+ instructionsBuilder.build()).build();
+
+ flows.createTunnelFlow((short) 3, 80, new NodeConnectorId(CONNECTOR_0), ordinals, ofWriter);
+ verify(ofWriter, times(1)).writeFlow(nodeId, tableId, testFlow);
+ }
+
+ @Test
+ public void createBroadcastFlow() throws Exception {
+ Endpoint testEndpoint = endpointBuilder(new IpAddress(new Ipv4Address(IPV4_1)), new MacAddress(MAC_0),
+ new NodeConnectorId(CONNECTOR_1), null, null).build();
+
+ when(ctx.getEndpointManager()).thenReturn(endpointManager);
+ when(ctx.getTenant(Mockito.any(TenantId.class))).thenReturn(indexedTenantBuilder());
+ when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
+
+ OrdinalFactory.EndpointFwdCtxOrdinals ordinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, testEndpoint);
+
+ InOrder order = inOrder(ctx);
+ order.verify(ctx, times(1)).getEndpointManager();
+ order.verify(ctx, times(1)).getCurrentPolicy();
+ verify(ctx, times(2)).getTenant(new TenantId(TENANT_ID));
+ assertNotNull(ordinals);
+
+ Action reg5 = FlowUtils.nxLoadRegAction(NxmNxReg5.class, BigInteger.valueOf(0));
+ InstructionsBuilder instructionsBuilder = new InstructionsBuilder();
+ List<Instruction> instructions = new ArrayList<>();
+ InstructionBuilder ordinalsInstruction = new InstructionBuilder();
+ ordinalsInstruction.setInstruction(FlowUtils.applyActionIns(reg5)).setOrder(0);
+ InstructionBuilder goToInstruction = new InstructionBuilder();
+ goToInstruction.setInstruction(FlowUtils.gotoTableIns((short) 3)).setOrder(1);
+ instructions.add(ordinalsInstruction.build());
+ instructions.add(goToInstruction.build());
+ instructionsBuilder.setInstruction(instructions);
+
+ MatchBuilder matchBuilder = new MatchBuilder();
+ matchBuilder.setInPort(new NodeConnectorId(CONNECTOR_1));
+ FlowUtils.addNxTunIdMatch(matchBuilder, 0);
+ Match match = matchBuilder.build();
+
+ Flow testFlow = flowBuilder(FlowIdUtils.newFlowId(tableId, FLOOD_ID, match), tableId, 80, match,
+ instructionsBuilder.build()).build();
+
+ flows.createBroadcastFlow((short) 3, 80, new NodeConnectorId(CONNECTOR_1), ordinals, ofWriter);
+ verify(ofWriter, times(1)).writeFlow(nodeId, tableId, testFlow);
+ }
+}
\ No newline at end of file
--- /dev/null
+package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.mapper.source;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InOrder;
+import org.mockito.Mockito;
+import org.opendaylight.groupbasedpolicy.dto.EgKey;
+import org.opendaylight.groupbasedpolicy.dto.PolicyInfo;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfContext;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.PolicyManager;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.endpoint.EndpointManager;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.OrdinalFactory;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.mapper.MapperUtilsTest;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.node.SwitchManager;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.Endpoint;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.overlay.rev150105.TunnelTypeVxlan;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import static org.mockito.Mockito.*;
+
+
+public class SourceMapperTest extends MapperUtilsTest {
+
+ @Before
+ public void init() {
+ tableId = 2;
+ ctx = mock(OfContext.class);
+ endpointManager = mock(EndpointManager.class);
+ switchManager = mock(SwitchManager.class);
+ policyInfo = mock(PolicyInfo.class);
+ policyManager = mock(PolicyManager.class);
+ ofWriter = mock(OfWriter.class);
+ }
+
+ @Test
+ public void syncFlows_tunnelPortTest() {
+ Endpoint endpoint = endpointBuilder(new IpAddress(new Ipv4Address(IPV4_1)), new MacAddress(MAC_1),
+ new NodeConnectorId(CONNECTOR_0), null, null).build();
+ EndpointBuilder endpointBuilder = new EndpointBuilder(endpoint);
+ endpointBuilder.setEndpointGroup(new EndpointGroupId(EPG_ID));
+
+ // List of other endpoints (one entry is good enough)
+ HashSet<Endpoint> otherEndpoints = new HashSet<>();
+ Endpoint otherEndpoint = endpointBuilder(new IpAddress(new Ipv4Address(IPV4_2)), new MacAddress(MAC_1),
+ new NodeConnectorId(CONNECTOR_1), null, null).build();
+ EndpointBuilder otherEndpointBuilder = new EndpointBuilder(otherEndpoint);
+ otherEndpointBuilder.setEndpointGroup(new EndpointGroupId(ENDPOINT_GROUP_0));
+ List<EndpointGroupId> endpointGroupIds = new ArrayList<>();
+ endpointGroupIds.add(new EndpointGroupId(ENDPOINT_GROUP_1));
+ endpointGroupIds.add(new EndpointGroupId(ENDPOINT_GROUP_2));
+ otherEndpointBuilder.setEndpointGroups(endpointGroupIds);
+ otherEndpoints.add(otherEndpointBuilder.build());
+
+ // NodeId set
+ Set<NodeId> nodeIds = new HashSet<>();
+ nodeIds.add(nodeId);
+ nodeIds.add(new NodeId("some Id"));
+
+ SourceMapper sourceMapper = new SourceMapper(ctx, tableId);
+
+ when(ctx.getPolicyManager()).thenReturn(policyManager);
+ when(ctx.getSwitchManager()).thenReturn(switchManager);
+ when(ctx.getEndpointManager()).thenReturn(endpointManager);
+ when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
+ when(ctx.getTenant(Mockito.any(TenantId.class))).thenReturn(indexedTenantBuilder());
+ when(policyManager.getTABLEID_DESTINATION_MAPPER()).thenReturn((short) 3);
+ when(switchManager.getTunnelPort(nodeId, TunnelTypeVxlan.class)).thenReturn(new NodeConnectorId(CONNECTOR_1));
+ when(endpointManager.getEndpointsForGroup(Mockito.any(EgKey.class))).thenReturn(otherEndpoints);
+
+ SourceMapperFlows flows = mock(SourceMapperFlows.class);
+
+ sourceMapper.syncFlows(flows, endpointBuilder.build(), nodeId, ofWriter);
+
+ // Verify method usage
+ verify(ctx, times(3)).getEndpointManager();
+ verify(ctx, times(5)).getTenant(Mockito.any(TenantId.class));
+ verify(ctx.getPolicyManager(), times(1)).getTABLEID_DESTINATION_MAPPER();
+ verify(ctx.getSwitchManager(), times(1)).getTunnelPort(nodeId, TunnelTypeVxlan.class);
+ verify(ctx.getEndpointManager(), times(1)).getEndpointsForGroup(Mockito.any(EgKey.class));
+
+ // Verify order
+ InOrder order = inOrder(ctx, flows);
+ order.verify(flows, atLeastOnce()).dropFlow(Mockito.anyInt(), Mockito.anyLong(), eq(ofWriter));
+ order.verify(ctx, times(1)).getPolicyManager();
+ order.verify(ctx, times(1)).getSwitchManager();
+ order.verify(ctx, times(1)).getCurrentPolicy();
+ order.verify(ctx, times(1)).getEndpointManager();
+ order.verify(flows, atLeastOnce()).createTunnelFlow(Mockito.anyShort(), Mockito.anyInt(),
+ Mockito.any(NodeConnectorId.class), Mockito.any(OrdinalFactory.EndpointFwdCtxOrdinals.class),
+ eq(ofWriter));
+ order.verify(flows, atLeastOnce()).createBroadcastFlow(Mockito.anyShort(), Mockito.anyInt(),
+ Mockito.any(NodeConnectorId.class), Mockito.any(OrdinalFactory.EndpointFwdCtxOrdinals.class),
+ eq(ofWriter));
+ }
+
+ @Test
+ public void syncFlows_endpointGroupsOnly() {
+ Endpoint endpoint = endpointBuilder(new IpAddress(new Ipv4Address(IPV4_2)), new MacAddress(MAC_1),
+ new NodeConnectorId(CONNECTOR_1), null, null).build();
+ EndpointBuilder endpointBuilder = new EndpointBuilder(endpoint);
+ endpointBuilder.setEndpointGroup(new EndpointGroupId(ENDPOINT_GROUP_0));
+ List<EndpointGroupId> endpointGroupIds = new ArrayList<>();
+ endpointGroupIds.add(new EndpointGroupId(ENDPOINT_GROUP_1));
+ endpointGroupIds.add(new EndpointGroupId(ENDPOINT_GROUP_2));
+ endpointBuilder.setEndpointGroups(endpointGroupIds);
+
+ SourceMapper sourceMapper = new SourceMapper(ctx, tableId);
+
+ when(ctx.getPolicyManager()).thenReturn(policyManager);
+ when(ctx.getSwitchManager()).thenReturn(switchManager);
+ when(ctx.getEndpointManager()).thenReturn(endpointManager);
+ when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
+ when(ctx.getTenant(Mockito.any(TenantId.class))).thenReturn(indexedTenantBuilder());
+ when(policyManager.getTABLEID_DESTINATION_MAPPER()).thenReturn((short) 3);
+
+ SourceMapperFlows flows = mock(SourceMapperFlows.class);
+
+ sourceMapper.syncFlows(flows, endpointBuilder.build(), nodeId, ofWriter);
+
+ // Verify OfContext method usage
+ verify(ctx, times(3)).getTenant(Mockito.any(TenantId.class));
+ verify(ctx.getPolicyManager(), times(1)).getTABLEID_DESTINATION_MAPPER();
+ verify(ctx.getSwitchManager(), times(1)).getTunnelPort(nodeId, TunnelTypeVxlan.class);
+
+ // Verify order
+ InOrder order = inOrder(ctx, flows);
+ order.verify(flows, atLeastOnce()).dropFlow(Mockito.anyInt(), Mockito.anyLong(), eq(ofWriter));
+ order.verify(ctx, times(1)).getPolicyManager();
+ order.verify(ctx, times(1)).getSwitchManager();
+ order.verify(ctx, times(3)).getTenant(Mockito.any(TenantId.class));
+ order.verify(ctx, times(1)).getEndpointManager();
+ order.verify(ctx, times(1)).getCurrentPolicy();
+ order.verify(flows, atLeastOnce()).synchronizeEp(Mockito.anyShort(), Mockito.anyInt(),
+ Mockito.any(OrdinalFactory.EndpointFwdCtxOrdinals.class), Mockito.any(MacAddress.class),
+ Mockito.any(NodeConnectorId.class), eq(ofWriter));
+ }
+}
\ No newline at end of file