package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.mapper.destination;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.anyShort;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.ARP;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.IPv4;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.IPv6;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.RegMatch;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.addNxRegMatch;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.applyActionIns;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.bytesFromHexString;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.decNwTtlAction;
+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.groupAction;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.nxLoadArpOpAction;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.nxLoadArpShaAction;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.nxLoadArpSpaAction;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.nxLoadRegAction;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.nxLoadTunIPv4Action;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.nxLoadTunIdAction;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.nxMoveArpShaToArpThaAction;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.nxMoveArpSpaToArpTpaAction;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.nxMoveEthSrcToEthDstAction;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.outputAction;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.setDlDstAction;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.setDlSrcAction;
+
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
import org.junit.Before;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mockito;
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.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.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.inet.types.rev100924.Ipv6Prefix;
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.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.EndpointL3PrefixBuilder;
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.policy.rev140421.tenants.Tenant;
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.PolicyBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.Subnet;
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.openflowjava.nx.match.rev140421.NxmNxReg7;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-
-import java.lang.reflect.Field;
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import static org.mockito.Mockito.*;
-import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.*;
-@RunWith(PowerMockRunner.class)
-@PrepareForTest({ OrdinalFactory.class })
public class DestinationMapperFlowsTest extends MapperUtilsTest {
private DestinationMapperFlows flows;
+ private DestinationMapperUtils utils;
+ private Tenant tenant;
+ private IndexedTenant indexedTenant;
@Before
public void init() throws Exception {
policyInfo = mock(PolicyInfo.class);
ctx = mock(OfContext.class);
ofWriter = mock(OfWriter.class);
+
tableId = 3;
- flows = new DestinationMapperFlows(new DestinationMapperUtils(ctx), NODE_ID, tableId);
- resetPolicyOrdinalCounterValue();
+
+ tenant = buildTenant().build();
+ indexedTenant = new IndexedTenant(tenant);
+
+ when(ctx.getTenant(TENANT_ID)).thenReturn(indexedTenant);
+ when(ctx.getEndpointManager()).thenReturn(endpointManager);
+ when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
+
+ utils = new DestinationMapperUtils(ctx);
+ flows = new DestinationMapperFlows(utils, NODE_ID, tableId);
+ OrdinalFactory.resetPolicyOrdinalValue();
}
@Test
externalConnectors.add(new NodeConnectorId(CONNECTOR_0));
externalConnectors.add(new NodeConnectorId(CONNECTOR_1));
- when(ctx.getTenant(Mockito.any(TenantId.class))).thenReturn(getTestIndexedTenant());
- when(ctx.getEndpointManager()).thenReturn(endpointManager);
- when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
-
flows.createExternalL2Flow(tableId, 100, endpointBuilder.build(), externalConnectors, ofWriter);
- verify(ctx, times(3)).getTenant(any(TenantId.class));
- verify(ctx, times(1)).getEndpointManager();
- verify(ctx, times(1)).getCurrentPolicy();
+
verifyZeroInteractions(ofWriter);
}
Set<NodeConnectorId> externalConnectors = new HashSet<>();
externalConnectors.add(new NodeConnectorId(OPENFLOW + CONNECTOR_0.getValue()));
externalConnectors.add(new NodeConnectorId(OPENFLOW + CONNECTOR_1.getValue()));
- Endpoint endpoint = endpointBuilder.build();
-
+ Endpoint endpoint = endpointBuilder.setTenant(tenant.getId()).build();
- MatchBuilder matchBuilder = new MatchBuilder()
- .setEthernetMatch(ethernetMatch(null, endpoint.getMacAddress(), null));
- addNxRegMatch(matchBuilder, RegMatch.of(NxmNxReg4.class, (long) 3));
+ MatchBuilder matchBuilder =
+ new MatchBuilder().setEthernetMatch(ethernetMatch(null, endpoint.getMacAddress(), null));
+ OrdinalFactory.EndpointFwdCtxOrdinals ord = utils.getEndpointOrdinals(endpoint);
+ addNxRegMatch(matchBuilder, RegMatch.of(NxmNxReg4.class, (long) ord.getBdId()));
Match match = matchBuilder.build();
List<Action> applyActions = new ArrayList<>();
int order = 0;
Instruction applyActionsIns = new InstructionBuilder().setOrder(order++)
- .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()])))
- .build();
- Instruction gotoTable = new InstructionBuilder().setOrder(order)
- .setInstruction(gotoTableIns(tableId))
- .build();
+ .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()])))
+ .build();
+ Instruction gotoTable = new InstructionBuilder().setOrder(order).setInstruction(gotoTableIns(tableId)).build();
ArrayList<Instruction> instructions = new ArrayList<>();
instructions.add(applyActionsIns);
FlowId flowId = FlowIdUtils.newFlowId(tableId, "externalL2", match);
Flow flow = buildFlow(flowId, tableId, 100, match, instructionsBuilder.build()).build();
- when(ctx.getTenant(Mockito.any(TenantId.class))).thenReturn(getTestIndexedTenant());
- when(ctx.getEndpointManager()).thenReturn(endpointManager);
- when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
-
flows.createExternalL2Flow(tableId, 100, endpointBuilder.build(), externalConnectors, ofWriter);
- verify(ctx, times(3)).getTenant(any(TenantId.class));
- verify(ctx, times(1)).getEndpointManager();
- verify(ctx, times(1)).getCurrentPolicy();
+
verify(ofWriter, times(1)).writeFlow(eq(NODE_ID), eq(tableId), eq(flow));
}
externalConnectors.add(new NodeConnectorId(CONNECTOR_0));
externalConnectors.add(new NodeConnectorId(CONNECTOR_1));
- when(ctx.getTenant(Mockito.any(TenantId.class))).thenReturn(getTestIndexedTenant());
- when(ctx.getEndpointManager()).thenReturn(endpointManager);
- when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
-
flows.createExternalL3RoutedFlow(tableId, 90, endpoint, gateway, l3AddressBuilder.build(), externalConnectors,
ofWriter);
- verify(ctx, times(3)).getTenant(any(TenantId.class));
- verify(ctx, times(1)).getEndpointManager();
- verify(ctx, times(1)).getCurrentPolicy();
verifyZeroInteractions(ofWriter);
}
externalConnectors.add(new NodeConnectorId(CONNECTOR_0));
externalConnectors.add(new NodeConnectorId(CONNECTOR_1));
- when(ctx.getTenant(Mockito.any(TenantId.class))).thenReturn(getTestIndexedTenant());
- when(ctx.getEndpointManager()).thenReturn(endpointManager);
- when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
-
flows.createExternalL3RoutedFlow(tableId, 90, endpoint, gateway, l3AddressBuilder.build(), externalConnectors,
ofWriter);
- verify(ctx, times(3)).getTenant(any(TenantId.class));
- verify(ctx, times(1)).getEndpointManager();
- verify(ctx, times(1)).getCurrentPolicy();
verifyZeroInteractions(ofWriter);
}
applyActions.addAll(l3ApplyActions);
MatchBuilder matchBuilder = new MatchBuilder().setEthernetMatch(ethernetMatch(null, MAC_1, IPv4))
- .setLayer3Match(new Ipv4MatchBuilder()
- .setIpv4Destination(new Ipv4Prefix(IPV4_0.getValue() + IP_PREFIX_32)).build());
+ .setLayer3Match(new Ipv4MatchBuilder().setIpv4Destination(new Ipv4Prefix(IPV4_0.getValue() + IP_PREFIX_32))
+ .build());
addNxRegMatch(matchBuilder, RegMatch.of(NxmNxReg6.class, (long) 5));
Match match = matchBuilder.build();
int order = 0;
Instruction applyActionsIns = new InstructionBuilder().setOrder(order++)
- .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()])))
- .build();
- Instruction gotoTable = new InstructionBuilder().setOrder(order)
- .setInstruction(gotoTableIns(tableId))
- .build();
+ .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()])))
+ .build();
+ Instruction gotoTable = new InstructionBuilder().setOrder(order).setInstruction(gotoTableIns(tableId)).build();
ArrayList<Instruction> l3instructions = new ArrayList<>();
l3instructions.add(applyActionsIns);
l3instructions.add(gotoTable);
FlowId flowid = FlowIdUtils.newFlowId(tableId, "externalL3", match);
Flow flow = buildFlow(flowid, tableId, 90, match, instructionsBuilder.build()).build();
- when(ctx.getTenant(Mockito.any(TenantId.class))).thenReturn(getTestIndexedTenant());
- when(ctx.getEndpointManager()).thenReturn(endpointManager);
- when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
-
flows.createExternalL3RoutedFlow(tableId, 90, endpoint, gateway, l3AddressBuilder.build(), externalConnectors,
ofWriter);
- verify(ctx, times(3)).getTenant(any(TenantId.class));
- verify(ctx, times(1)).getEndpointManager();
- verify(ctx, times(1)).getCurrentPolicy();
verify(ofWriter, times(1)).writeFlow(eq(NODE_ID), eq(tableId), eq(flow));
}
applyActions.addAll(l3ApplyActions);
MatchBuilder matchBuilder = new MatchBuilder().setEthernetMatch(ethernetMatch(null, MAC_1, IPv6))
- .setLayer3Match(new Ipv6MatchBuilder()
- .setIpv6Destination(new Ipv6Prefix(IPV6_1.getValue() + IP_PREFIX_128)).build());
+ .setLayer3Match(new Ipv6MatchBuilder().setIpv6Destination(new Ipv6Prefix(IPV6_1.getValue() + IP_PREFIX_128))
+ .build());
addNxRegMatch(matchBuilder, RegMatch.of(NxmNxReg6.class, (long) 0));
Match match = matchBuilder.build();
int order = 0;
Instruction applyActionsIns = new InstructionBuilder().setOrder(order++)
- .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()])))
- .build();
- Instruction gotoTable = new InstructionBuilder().setOrder(order)
- .setInstruction(gotoTableIns(tableId))
- .build();
+ .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()])))
+ .build();
+ Instruction gotoTable = new InstructionBuilder().setOrder(order).setInstruction(gotoTableIns(tableId)).build();
ArrayList<Instruction> l3instructions = new ArrayList<>();
l3instructions.add(applyActionsIns);
l3instructions.add(gotoTable);
FlowId flowid = FlowIdUtils.newFlowId(tableId, "externalL3", match);
Flow flow = buildFlow(flowid, tableId, 90, match, instructionsBuilder.build()).build();
- when(ctx.getTenant(Mockito.any(TenantId.class))).thenReturn(getTestIndexedTenant());
- when(ctx.getEndpointManager()).thenReturn(endpointManager);
- when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
-
flows.createExternalL3RoutedFlow(tableId, 90, endpoint, gateway, l3AddressBuilder.build(), externalConnectors,
ofWriter);
- verify(ctx, times(3)).getTenant(any(TenantId.class));
- verify(ctx, times(1)).getEndpointManager();
- verify(ctx, times(1)).getCurrentPolicy();
verify(ofWriter, times(1)).writeFlow(eq(NODE_ID), eq(tableId), eq(flow));
}
EndpointBuilder endpointBuilder = buildEndpoint(IPV6_1, MAC_0, CONNECTOR_0);
Endpoint endpoint = endpointBuilder.build();
- when(ctx.getTenant(Mockito.any(TenantId.class))).thenReturn(getTestIndexedTenant());
- when(ctx.getEndpointManager()).thenReturn(endpointManager);
- when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
-
flows.createLocalL2Flow(tableId, 80, endpoint, ofWriter);
- verify(ctx, times(3)).getTenant(any(TenantId.class));
- verify(ctx, times(1)).getEndpointManager();
- verify(ctx, times(1)).getCurrentPolicy();
verifyZeroInteractions(ofWriter);
}
NodeConnectorId connectorId = new NodeConnectorId(OPENFLOW + CONNECTOR_0.getValue());
EndpointBuilder endpointBuilder = buildEndpoint(IPV6_1, MAC_0, connectorId);
endpointBuilder.setNetworkContainment(SUBNET_0);
- Endpoint endpoint = endpointBuilder.build();
+ Endpoint endpoint = endpointBuilder.setTenant(tenant.getId()).build();
List<Action> applyActions = new ArrayList<>();
applyActions.add(nxLoadRegAction(NxmNxReg2.class, BigInteger.valueOf(1)));
int order = 0;
Instruction applyActionsIns = new InstructionBuilder().setOrder(order++)
- .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()])))
- .build();
- Instruction gotoTable = new InstructionBuilder().setOrder(order)
- .setInstruction(gotoTableIns(tableId))
- .build();
+ .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()])))
+ .build();
+ Instruction gotoTable = new InstructionBuilder().setOrder(order).setInstruction(gotoTableIns(tableId)).build();
ArrayList<Instruction> instructions = new ArrayList<>();
instructions.add(applyActionsIns);
InstructionsBuilder instructionsBuilder = new InstructionsBuilder();
instructionsBuilder.setInstruction(instructions);
- MatchBuilder matchBuilder = new MatchBuilder().setEthernetMatch(ethernetMatch(null, endpoint.getMacAddress(),
- null));
- addNxRegMatch(matchBuilder, RegMatch.of(NxmNxReg4.class, (long) 3));
+ MatchBuilder matchBuilder =
+ new MatchBuilder().setEthernetMatch(ethernetMatch(null, endpoint.getMacAddress(), null));
+ OrdinalFactory.EndpointFwdCtxOrdinals ord = utils.getEndpointOrdinals(endpoint);
+ addNxRegMatch(matchBuilder, RegMatch.of(NxmNxReg4.class, (long) ord.getBdId()));
Match match = matchBuilder.build();
Flow flow = buildFlow(FlowIdUtils.newFlowId(tableId, "localL2", match), tableId, 80, match,
instructionsBuilder.build()).build();
- when(ctx.getTenant(Mockito.any(TenantId.class))).thenReturn(getTestIndexedTenant());
- when(ctx.getEndpointManager()).thenReturn(endpointManager);
- when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
-
flows.createLocalL2Flow(tableId, 80, endpoint, ofWriter);
- verify(ctx, times(3)).getTenant(any(TenantId.class));
- verify(ctx, times(1)).getEndpointManager();
- verify(ctx, times(1)).getCurrentPolicy();
verify(ofWriter, times(1)).writeFlow(eq(NODE_ID), eq(tableId), eq(flow));
}
destSubnetBuilder.setId(SUBNET_1);
Subnet destSubnet = destSubnetBuilder.build();
- when(ctx.getTenant(any(TenantId.class))).thenReturn(getTestIndexedTenant());
- when(ctx.getEndpointManager()).thenReturn(endpointManager);
-
flows.createLocalL3RoutedFlow(tableId, 80, endpoint, null, localSubnet, destSubnet, ofWriter);
- verify(ctx, times(1)).getTenant(any(TenantId.class));
- verify(ctx, times(1)).getEndpointManager();
+
verifyZeroInteractions(ofWriter);
}
destSubnetBuilder.setParent(L2FD_ID);
Subnet destSubnet = destSubnetBuilder.build();
- when(ctx.getTenant(any(TenantId.class))).thenReturn(getTestIndexedTenant());
- when(ctx.getEndpointManager()).thenReturn(endpointManager);
-
flows.createLocalL3RoutedFlow(tableId, 80, endpoint, null, localSubnet, destSubnet, ofWriter);
- verify(ctx, times(3)).getTenant(any(TenantId.class));
- verify(ctx, times(3)).getEndpointManager();
+
verifyZeroInteractions(ofWriter);
}
l3AddressBuilder.setIpAddress(null);
L3Address l3Address = l3AddressBuilder.build();
- when(ctx.getTenant(any(TenantId.class))).thenReturn(getTestIndexedTenant());
- when(ctx.getEndpointManager()).thenReturn(endpointManager);
- when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
-
flows.createLocalL3RoutedFlow(tableId, 80, endpoint, l3Address, localSubnet, destSubnet, ofWriter);
- verify(ctx, times(4)).getTenant(any(TenantId.class));
- verify(ctx, times(3)).getEndpointManager();
- verify(ctx, times(1)).getCurrentPolicy();
+
verifyZeroInteractions(ofWriter);
}
int order = 0;
Instruction applyActionsIns = new InstructionBuilder().setOrder(order++)
- .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()])))
- .build();
- Instruction gotoTable = new InstructionBuilder().setOrder(order)
- .setInstruction(gotoTableIns(tableId))
- .build();
+ .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()])))
+ .build();
+ Instruction gotoTable = new InstructionBuilder().setOrder(order).setInstruction(gotoTableIns(tableId)).build();
ArrayList<Instruction> l3instructions = new ArrayList<>();
l3instructions.add(applyActionsIns);
l3instructions.add(gotoTable);
MatchBuilder matchBuilder = new MatchBuilder().setEthernetMatch(ethernetMatch(null, destMac, IPv4))
- .setLayer3Match(new Ipv4MatchBuilder().setIpv4Destination(new Ipv4Prefix(IPV4_0.getValue() + IP_PREFIX_32)).build());
+ .setLayer3Match(new Ipv4MatchBuilder().setIpv4Destination(new Ipv4Prefix(IPV4_0.getValue() + IP_PREFIX_32))
+ .build());
addNxRegMatch(matchBuilder, RegMatch.of(NxmNxReg6.class, (long) 5));
Match match = matchBuilder.build();
InstructionsBuilder instructionsBuilder = new InstructionsBuilder();
Flow flow = buildFlow(FlowIdUtils.newFlowId(tableId, "localL3", match), tableId, 80, match,
instructionsBuilder.build()).build();
- when(ctx.getTenant(any(TenantId.class))).thenReturn(getTestIndexedTenant());
- when(ctx.getEndpointManager()).thenReturn(endpointManager);
- when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
-
flows.createLocalL3RoutedFlow(tableId, 80, endpoint, l3Address, localSubnet, destSubnet, ofWriter);
- verify(ctx, times(4)).getTenant(any(TenantId.class));
- verify(ctx, times(3)).getEndpointManager();
- verify(ctx, times(1)).getCurrentPolicy();
+
verify(ofWriter, times(1)).writeFlow(eq(NODE_ID), eq(tableId), eq(flow));
}
MacAddress destMac = DestinationMapper.ROUTER_MAC;
OfOverlayContextBuilder ofOverlayContextBuilder = new OfOverlayContextBuilder();
ofOverlayContextBuilder.setNodeConnectorId(connectorId);
- EndpointBuilder endpointBuilder = buildEndpoint(IPV6_1,MAC_1, connectorId);
+ EndpointBuilder endpointBuilder = buildEndpoint(IPV6_1, MAC_1, connectorId);
endpointBuilder.addAugmentation(OfOverlayContext.class, ofOverlayContextBuilder.build());
endpointBuilder.setTenant(getTestIndexedTenant().getTenant().getId());
endpointBuilder.setNetworkContainment(SUBNET_0);
int order = 0;
Instruction applyActionsIns = new InstructionBuilder().setOrder(order++)
- .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()])))
- .build();
- Instruction gotoTable = new InstructionBuilder().setOrder(order)
- .setInstruction(gotoTableIns(tableId))
- .build();
+ .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()])))
+ .build();
+ Instruction gotoTable = new InstructionBuilder().setOrder(order).setInstruction(gotoTableIns(tableId)).build();
ArrayList<Instruction> l3instructions = new ArrayList<>();
l3instructions.add(applyActionsIns);
l3instructions.add(gotoTable);
MatchBuilder matchBuilder = new MatchBuilder().setEthernetMatch(ethernetMatch(null, destMac, IPv6))
- .setLayer3Match(new Ipv6MatchBuilder().setIpv6Destination(new Ipv6Prefix(IPV6_1.getValue() + IP_PREFIX_128)).build());
+ .setLayer3Match(new Ipv6MatchBuilder().setIpv6Destination(new Ipv6Prefix(IPV6_1.getValue() + IP_PREFIX_128))
+ .build());
addNxRegMatch(matchBuilder, RegMatch.of(NxmNxReg6.class, (long) 5));
Match match = matchBuilder.build();
InstructionsBuilder instructionsBuilder = new InstructionsBuilder();
Flow flow = buildFlow(FlowIdUtils.newFlowId(tableId, "localL3", match), tableId, 80, match,
instructionsBuilder.build()).build();
- when(ctx.getTenant(any(TenantId.class))).thenReturn(getTestIndexedTenant());
- when(ctx.getEndpointManager()).thenReturn(endpointManager);
- when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
-
flows.createLocalL3RoutedFlow(tableId, 80, endpoint, l3Address, localSubnet, destSubnet, ofWriter);
- verify(ctx, times(4)).getTenant(any(TenantId.class));
- verify(ctx, times(3)).getEndpointManager();
- verify(ctx, times(1)).getCurrentPolicy();
+
verify(ofWriter, times(1)).writeFlow(eq(NODE_ID), eq(tableId), eq(flow));
}
public void createRemoteL2Flow_exceptionCaught() {
EndpointBuilder endpointBuilder = buildEndpoint(IPV6_1, MAC_1, CONNECTOR_0);
- when(ctx.getTenant(any(TenantId.class))).thenReturn(getTestIndexedTenant());
- when(ctx.getEndpointManager()).thenReturn(endpointManager);
- when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
-
flows.createRemoteL2Flow(tableId, 70, endpointBuilder.build(), null, null, new NodeConnectorId(CONNECTOR_1),
ofWriter);
- verify(ctx, times(3)).getTenant(any(TenantId.class));
- verify(ctx, times(1)).getEndpointManager();
- verify(ctx, times(1)).getCurrentPolicy();
+
verifyZeroInteractions(ofWriter);
}
public void createRemoteL2Flow_ipV4() {
NodeConnectorId connectorId = new NodeConnectorId(OPENFLOW + CONNECTOR_1.getValue());
IpAddress ipAddress = new IpAddress(IPV4_0);
- EndpointBuilder endpointBuilder = buildEndpoint(IPV4_0, MAC_1, CONNECTOR_0);
- EndpointBuilder peerEndpointBuilder = buildEndpoint(IPV4_1, MAC_0, CONNECTOR_1);
+ Endpoint endpoint = buildEndpoint(IPV4_0, MAC_1, CONNECTOR_0).setTenant(tenant.getId()).build();
+ Endpoint peerEndpoint = buildEndpoint(IPV4_1, MAC_0, CONNECTOR_1).build();
List<Action> applyActions = new ArrayList<>();
applyActions.add(nxLoadRegAction(NxmNxReg2.class, BigInteger.valueOf(1)));
int order = 0;
Instruction applyActionsIns = new InstructionBuilder().setOrder(order++)
- .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()])))
- .build();
- Instruction gotoTable = new InstructionBuilder().setOrder(order)
- .setInstruction(gotoTableIns(tableId))
- .build();
+ .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()])))
+ .build();
+ Instruction gotoTable = new InstructionBuilder().setOrder(order).setInstruction(gotoTableIns(tableId)).build();
ArrayList<Instruction> instructions = new ArrayList<>();
instructions.add(applyActionsIns);
InstructionsBuilder instructionsBuilder = new InstructionsBuilder();
instructionsBuilder.setInstruction(instructions);
- MatchBuilder matchBuilder = new MatchBuilder()
- .setEthernetMatch(ethernetMatch(null, MAC_0, null));
- addNxRegMatch(matchBuilder, RegMatch.of(NxmNxReg4.class, (long) 3));
+ MatchBuilder matchBuilder = new MatchBuilder().setEthernetMatch(ethernetMatch(null, MAC_0, null));
+ OrdinalFactory.EndpointFwdCtxOrdinals ord = utils.getEndpointOrdinals(endpoint);
+ addNxRegMatch(matchBuilder, RegMatch.of(NxmNxReg4.class, (long) ord.getBdId()));
Match match = matchBuilder.build();
Flow flow = buildFlow(FlowIdUtils.newFlowId(tableId, "remoteL2", match), tableId, 70, match,
instructionsBuilder.build()).build();
- when(ctx.getTenant(any(TenantId.class))).thenReturn(getTestIndexedTenant());
- when(ctx.getEndpointManager()).thenReturn(endpointManager);
- when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
+ flows.createRemoteL2Flow(tableId, 70, endpoint, peerEndpoint, ipAddress, connectorId, ofWriter);
- flows.createRemoteL2Flow(tableId, 70, endpointBuilder.build(), peerEndpointBuilder.build(), ipAddress,
- connectorId, ofWriter);
- verify(ctx, times(3)).getTenant(any(TenantId.class));
- verify(ctx, times(1)).getEndpointManager();
- verify(ctx, times(1)).getCurrentPolicy();
verify(ofWriter, times(1)).writeFlow(eq(NODE_ID), eq(tableId), eq(flow));
}
EndpointBuilder endpointBuilder = buildEndpoint(IPV6_1, MAC_1, CONNECTOR_0);
EndpointBuilder peerEndpointBuilder = buildEndpoint(IPV6_2, MAC_0, CONNECTOR_0);
- when(ctx.getTenant(any(TenantId.class))).thenReturn(getTestIndexedTenant());
- when(ctx.getEndpointManager()).thenReturn(endpointManager);
- when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
-
flows.createRemoteL2Flow(tableId, 70, endpointBuilder.build(), peerEndpointBuilder.build(), ipAddress,
connectorId, ofWriter);
- verify(ctx, times(3)).getTenant(any(TenantId.class));
- verify(ctx, times(1)).getEndpointManager();
- verify(ctx, times(1)).getCurrentPolicy();
+
verifyZeroInteractions(ofWriter);
}
localSubnetBuilder.setParent(L2FD_ID);
Subnet localSubnet = localSubnetBuilder.build();
- when(ctx.getTenant(Mockito.any(TenantId.class))).thenReturn(getTestIndexedTenant());
- when(ctx.getEndpointManager()).thenReturn(endpointManager);
- when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
-
flows.createRemoteL3RoutedFlow(tableId, 60, endpoint, null, destSubnet, null, null, localSubnet, ofWriter);
- verify(ctx, times(4)).getTenant(any(TenantId.class));
- verify(ctx, times(2)).getEndpointManager();
- verify(ctx, times(1)).getCurrentPolicy();
+
verifyZeroInteractions(ofWriter);
}
localSubnetBuilder.setParent(L2FD_ID);
Subnet localSubnet = localSubnetBuilder.build();
- when(ctx.getTenant(Mockito.any(TenantId.class))).thenReturn(getTestIndexedTenant());
- when(ctx.getEndpointManager()).thenReturn(endpointManager);
- when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
-
flows.createRemoteL3RoutedFlow(tableId, 60, endpoint, null, destSubnet, null, null, localSubnet, ofWriter);
- verify(ctx, times(4)).getTenant(any(TenantId.class));
- verify(ctx, times(3)).getEndpointManager();
- verify(ctx, times(1)).getCurrentPolicy();
+
verifyZeroInteractions(ofWriter);
}
public void createRemoteL3RoutedFlow_incorrectPortId() {
IpAddress ipAddress = new IpAddress(IPV4_0);
NodeConnectorId connectorId = new NodeConnectorId(CONNECTOR_0);
- EndpointBuilder endpointBuilder = buildEndpoint(IPV6_1,MAC_1,CONNECTOR_0);
+ EndpointBuilder endpointBuilder = buildEndpoint(IPV6_1, MAC_1, CONNECTOR_0);
endpointBuilder.setNetworkContainment(SUBNET_0);
Endpoint endpoint = endpointBuilder.build();
-
SubnetBuilder destSubnetBuilder = new SubnetBuilder();
destSubnetBuilder.setId(SUBNET_1);
destSubnetBuilder.setParent(L2FD_ID);
localSubnetBuilder.setVirtualRouterIp(new IpAddress(IPV4_1));
Subnet localSubnet = localSubnetBuilder.build();
- when(ctx.getTenant(Mockito.any(TenantId.class))).thenReturn(getTestIndexedTenant());
- when(ctx.getEndpointManager()).thenReturn(endpointManager);
- when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
-
flows.createRemoteL3RoutedFlow(tableId, 60, endpoint, null, destSubnet, ipAddress, connectorId, localSubnet,
ofWriter);
- verify(ctx, times(4)).getTenant(any(TenantId.class));
- verify(ctx, times(3)).getEndpointManager();
- verify(ctx, times(1)).getCurrentPolicy();
+
verifyZeroInteractions(ofWriter);
}
applyActions.add(nxLoadTunIPv4Action(IPV4_1.getValue(), false));
applyActions.addAll(l3ApplyActions);
Instruction applyActionsIns = new InstructionBuilder().setOrder(0)
- .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()])))
- .build();
- Instruction gotoTable = new InstructionBuilder().setOrder(1)
- .setInstruction(gotoTableIns(tableId))
- .build();
+ .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()])))
+ .build();
+ Instruction gotoTable = new InstructionBuilder().setOrder(1).setInstruction(gotoTableIns(tableId)).build();
ArrayList<Instruction> l3instructions = new ArrayList<>();
l3instructions.add(applyActionsIns);
l3instructions.add(gotoTable);
instructionsBuilder.setInstruction(l3instructions);
MatchBuilder matchBuilder = new MatchBuilder().setEthernetMatch(ethernetMatch(null, routerMac, IPv4))
- .setLayer3Match(new Ipv4MatchBuilder().setIpv4Destination(new Ipv4Prefix(IPV4_1.getValue() + IP_PREFIX_32)).build());
+ .setLayer3Match(new Ipv4MatchBuilder().setIpv4Destination(new Ipv4Prefix(IPV4_1.getValue() + IP_PREFIX_32))
+ .build());
addNxRegMatch(matchBuilder, RegMatch.of(NxmNxReg6.class, (long) 5));
Match match = matchBuilder.build();
Flow flow = buildFlow(FlowIdUtils.newFlowId(tableId, "remoteL3", match), tableId, 60, match,
instructionsBuilder.build()).build();
- when(ctx.getTenant(Mockito.any(TenantId.class))).thenReturn(getTestIndexedTenant());
- when(ctx.getEndpointManager()).thenReturn(endpointManager);
- when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
+ flows.createRemoteL3RoutedFlow(tableId, 60, endpoint, l3Address, destSubnet, ipAddress, connectorId,
+ localSubnet, ofWriter);
- flows.createRemoteL3RoutedFlow(tableId, 60, endpoint, l3Address, destSubnet, ipAddress, connectorId, localSubnet,
- ofWriter);
- verify(ctx, times(4)).getTenant(any(TenantId.class));
- verify(ctx, times(3)).getEndpointManager();
- verify(ctx, times(1)).getCurrentPolicy();
verify(ofWriter, times(1)).writeFlow(eq(NODE_ID), eq(tableId), eq(flow));
}
localSubnetBuilder.setVirtualRouterIp(new IpAddress(IPV4_1));
Subnet localSubnet = localSubnetBuilder.build();
- when(ctx.getTenant(Mockito.any(TenantId.class))).thenReturn(getTestIndexedTenant());
- when(ctx.getEndpointManager()).thenReturn(endpointManager);
- when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
+ flows.createRemoteL3RoutedFlow(tableId, 60, endpoint, l3Address, destSubnet, ipAddress, connectorId,
+ localSubnet, ofWriter);
- flows.createRemoteL3RoutedFlow(tableId, 60, endpoint, l3Address, destSubnet, ipAddress, connectorId, localSubnet,
- ofWriter);
- verify(ctx, times(4)).getTenant(any(TenantId.class));
- verify(ctx, times(3)).getEndpointManager();
- verify(ctx, times(1)).getCurrentPolicy();
verifyZeroInteractions(ofWriter);
}
subnetBuilder.setVirtualRouterIp(new IpAddress(IPV4_0));
MatchBuilder matchBuilder = new MatchBuilder().setEthernetMatch(ethernetMatch(null, null, ARP))
- .setLayer3Match(new ArpMatchBuilder().setArpOp(1)
- .setArpTargetTransportAddress(new Ipv4Prefix(IPV4_0.getValue() + IP_PREFIX_32)).build());
+ .setLayer3Match(new ArpMatchBuilder().setArpOp(1)
+ .setArpTargetTransportAddress(new Ipv4Prefix(IPV4_0.getValue() + IP_PREFIX_32))
+ .build());
addNxRegMatch(matchBuilder, RegMatch.of(NxmNxReg6.class, (long) 5));
Match match = matchBuilder.build();
Flow flow = buildFlow(FlowIdUtils.newFlowId(tableId, "routerarp", match), tableId, 50, match,
instructionsBuilder.build()).build();
- when(ctx.getEndpointManager()).thenReturn(endpointManager);
flows.createRouterArpFlow(50, tenant, subnetBuilder.build(), ofWriter);
- verify(ctx, times(1)).getEndpointManager();
verify(ofWriter, times(1)).writeFlow(any(NodeId.class), anyShort(), eq(flow));
}
subnetBuilder.setParent(L2FD_ID);
subnetBuilder.setVirtualRouterIp(new IpAddress(IPV6_1));
- when(ctx.getEndpointManager()).thenReturn(endpointManager);
-
flows.createRouterArpFlow(50, tenant, subnetBuilder.build(), ofWriter);
- verify(ctx, times(1)).getEndpointManager();
verifyZeroInteractions(ofWriter);
}
EndpointBuilder endpointBuilder = buildEndpoint(IPV4_0, MAC_1, CONNECTOR_1);
endpointBuilder.setTenant(buildTenant().getId());
- when(ctx.getTenant(any(TenantId.class))).thenReturn(getTestIndexedTenant());
- when(ctx.getEndpointManager()).thenReturn(endpointManager);
- when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
-
OrdinalFactory.EndpointFwdCtxOrdinals ordinals = utils.getEndpointOrdinals(endpointBuilder.build());
- verify(ctx, times(3)).getTenant(any(TenantId.class));
- verify(ctx, times(1)).getEndpointManager();
- verify(ctx, times(1)).getCurrentPolicy();
-
- MatchBuilder matchBuilder = new MatchBuilder()
- .setEthernetMatch(new EthernetMatchBuilder()
- .setEthernetDestination(new EthernetDestinationBuilder().setAddress(MAC_0)
- .setMask(MAC_0).build())
- .build());
+ MatchBuilder matchBuilder = new MatchBuilder().setEthernetMatch(new EthernetMatchBuilder()
+ .setEthernetDestination(new EthernetDestinationBuilder().setAddress(MAC_0).setMask(MAC_0).build()).build());
addNxRegMatch(matchBuilder, FlowUtils.RegMatch.of(NxmNxReg5.class, (long) ordinals.getFdId()));
Match match = matchBuilder.build();
List<Action> actions = new ArrayList<>();
localSubnetBuilder.setParent(L2FD_ID);
Subnet localSubnet = localSubnetBuilder.build();
- when(ctx.getEndpointManager()).thenReturn(endpointManager);
-
flows.createL3PrefixFlow(tableId, 30, gatewayEp.build(), null, tenant, localSubnet, null, ofWriter);
- verify(ctx, times(1)).getEndpointManager();
+
verifyZeroInteractions(ofWriter);
}
externalPorts.add(new NodeConnectorId(CONNECTOR_0));
externalPorts.add(new NodeConnectorId(CONNECTOR_1));
- when(ctx.getEndpointManager()).thenReturn(endpointManager);
-
flows.createL3PrefixFlow(tableId, 30, gatewayEpBuilder.build(), null, tenant, localSubnet, externalPorts,
ofWriter);
- verify(ctx, times(1)).getEndpointManager();
+
verifyZeroInteractions(ofWriter);
}
applyActions.add(nxLoadRegAction(NxmNxReg7.class, BigInteger.valueOf(1)));
applyActions.addAll(l3ApplyActions);
Instruction applyActionsIns = new InstructionBuilder().setOrder(0)
- .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()])))
- .build();
- Instruction gotoTable = new InstructionBuilder().setOrder(1)
- .setInstruction(gotoTableIns(tableId))
- .build();
+ .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()])))
+ .build();
+ Instruction gotoTable = new InstructionBuilder().setOrder(1).setInstruction(gotoTableIns(tableId)).build();
ArrayList<Instruction> l3instructions = new ArrayList<>();
l3instructions.add(applyActionsIns);
l3instructions.add(gotoTable);
InstructionsBuilder instructionsBuilder = new InstructionsBuilder();
instructionsBuilder.setInstruction(l3instructions);
- MatchBuilder matchBuilder = new MatchBuilder().setEthernetMatch(ethernetMatch(null,
- DestinationMapper.ROUTER_MAC, IPv4));
+ MatchBuilder matchBuilder =
+ new MatchBuilder().setEthernetMatch(ethernetMatch(null, DestinationMapper.ROUTER_MAC, IPv4));
addNxRegMatch(matchBuilder, RegMatch.of(NxmNxReg6.class, (long) 5));
Match match = matchBuilder.build();
Flow flow = buildFlow(FlowIdUtils.newFlowId(tableId, "L3prefix", match), tableId, 30 + prefixLength, match,
instructionsBuilder.build()).build();
- when(ctx.getTenant(any(TenantId.class))).thenReturn(getTestIndexedTenant());
- when(ctx.getEndpointManager()).thenReturn(endpointManager);
- when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
+ flows.createL3PrefixFlow(tableId, 30, gatewayEp.build(), l3Prefix, tenant, localSubnet, null, ofWriter);
- flows.createL3PrefixFlow(tableId, 30, gatewayEp.build(), l3Prefix, tenant, localSubnet, null,
- ofWriter);
- verify(ctx, times(3)).getTenant(any(TenantId.class));
- verify(ctx, times(2)).getEndpointManager();
- verify(ctx, times(1)).getCurrentPolicy();
verify(ofWriter, times(1)).writeFlow(any(NodeId.class), anyShort(), eq(flow));
}
applyActions.add(nxLoadRegAction(NxmNxReg7.class, BigInteger.valueOf(0)));
applyActions.addAll(l3ApplyActions);
Instruction applyActionsIns = new InstructionBuilder().setOrder(0)
- .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()])))
- .build();
- Instruction gotoTable = new InstructionBuilder().setOrder(1)
- .setInstruction(gotoTableIns(tableId))
- .build();
+ .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()])))
+ .build();
+ Instruction gotoTable = new InstructionBuilder().setOrder(1).setInstruction(gotoTableIns(tableId)).build();
ArrayList<Instruction> l3instructions = new ArrayList<>();
l3instructions.add(applyActionsIns);
l3instructions.add(gotoTable);
InstructionsBuilder instructionsBuilder = new InstructionsBuilder();
instructionsBuilder.setInstruction(l3instructions);
- MatchBuilder matchBuilder = new MatchBuilder().setEthernetMatch(ethernetMatch(null,
- DestinationMapper.ROUTER_MAC, IPv6));
+ MatchBuilder matchBuilder =
+ new MatchBuilder().setEthernetMatch(ethernetMatch(null, DestinationMapper.ROUTER_MAC, IPv6));
addNxRegMatch(matchBuilder, RegMatch.of(NxmNxReg6.class, (long) 5));
Match match = matchBuilder.build();
Flow flow = buildFlow(FlowIdUtils.newFlowId(tableId, "L3prefix", match), tableId, 30 + prefixLength, match,
instructionsBuilder.build()).build();
- when(ctx.getTenant(any(TenantId.class))).thenReturn(getTestIndexedTenant());
- when(ctx.getEndpointManager()).thenReturn(endpointManager);
- when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
-
flows.createL3PrefixFlow(tableId, 30, gatewayEpBuilder.build(), l3Prefix, tenant, localSubnet, externalPorts,
ofWriter);
- verify(ctx, times(6)).getTenant(any(TenantId.class));
- verify(ctx, times(3)).getEndpointManager();
- verify(ctx, times(2)).getCurrentPolicy();
verify(ofWriter, times(1)).writeFlow(any(NodeId.class), anyShort(), eq(flow));
}
- private void resetPolicyOrdinalCounterValue() throws Exception {
- // TODO find better way, maybe fixed test method order?
- Field field = OrdinalFactory.class.getDeclaredField("policyOrdinal");
- field.setAccessible(true);
- field.set(null, new AtomicInteger(1));
- }
-}
\ No newline at end of file
+}