import java.util.HashMap;
import java.util.List;
import java.util.Objects;
+import java.util.Set;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
+import org.mockito.Matchers;
import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowTable.FlowCtx;
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.ofoverlay.rev140528.OfOverlayContext;
+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.model.match.types.rev131026.match.layer._3.match.ArpMatch;
import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;
import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6Match;
import org.slf4j.LoggerFactory;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
import static org.junit.Assert.*;
ReadWriteTransaction t = dosync(null);
ArgumentCaptor<Flow> ac = ArgumentCaptor.forClass(Flow.class);
verify(t, times(4)).put(eq(LogicalDatastoreType.CONFIGURATION),
- any(InstanceIdentifier.class), ac.capture());
+ Matchers.<InstanceIdentifier<Flow>>any(),
+ ac.capture(), anyBoolean());
int count = 0;
HashMap<String, FlowCtx> flowMap = new HashMap<>();
Long etherType = null;
if (f.getMatch() != null) {
etherType = f.getMatch().getEthernetMatch()
- .getEthernetType().getType().getValue().longValue();
+ .getEthernetType().getType().getValue();
}
if (f.getMatch() == null ||
- PortSecurity.ARP.equals(etherType) ||
- PortSecurity.IPv4.equals(etherType) ||
- PortSecurity.IPv6.equals(etherType)) {
+ FlowUtils.ARP.equals(etherType) ||
+ FlowUtils.IPv4.equals(etherType) ||
+ FlowUtils.IPv6.equals(etherType)) {
count += 1;
assertEquals(FlowUtils.dropInstructions(),
f.getInstructions());
- }
+ }
}
assertEquals(4, count);
t = dosync(flowMap);
verify(t, never()).put(any(LogicalDatastoreType.class),
- any(InstanceIdentifier.class),
- any(Flow.class));
+ Matchers.<InstanceIdentifier<Flow>>any(),
+ any(Flow.class), anyBoolean());
+ }
+
+ @Test
+ public void testNonLocalAllow() throws Exception {
+ switchManager
+ .addSwitch(new NodeId("openflow:1"),
+ new NodeConnectorId("openflow:1:1"),
+ ImmutableSet.of(new NodeConnectorId("openflow:1:2")),
+ null);
+
+ ReadWriteTransaction t = dosync(null);
+ ArgumentCaptor<Flow> ac = ArgumentCaptor.forClass(Flow.class);
+ verify(t, atLeastOnce()).put(eq(LogicalDatastoreType.CONFIGURATION),
+ Matchers.<InstanceIdentifier<Flow>>any(),
+ ac.capture(), anyBoolean());
+
+ int count = 0;
+ HashMap<String, FlowCtx> flowMap = new HashMap<>();
+ Set<String> ncs = ImmutableSet.of("openflow:1:1", "openflow:1:2");
+ for (Flow f : ac.getAllValues()) {
+ flowMap.put(f.getId().getValue(), new FlowCtx(f));
+ if (f.getMatch() != null && f.getMatch().getInPort() != null &&
+ ncs.contains(f.getMatch().getInPort().getValue())) {
+ assertEquals(f.getInstructions(),
+ FlowUtils.gotoTableInstructions((short)(table.getTableId()+1)));
+ count += 1;
+ }
+ }
+ assertEquals(2, count);
+
+ t = dosync(flowMap);
+ verify(t, never()).put(any(LogicalDatastoreType.class),
+ Matchers.<InstanceIdentifier<Flow>>any(),
+ any(Flow.class), anyBoolean());
}
@Test
public void testL2() throws Exception {
List<L3Address> l3 = Collections.emptyList();
- Endpoint ep = baseEP()
+ Endpoint ep = localEP()
.setL3Address(l3)
.build();
endpointManager.addEndpoint(ep);
- ReadWriteTransaction t = dosync(null);
+ ReadWriteTransaction t = dosync(null);
ArgumentCaptor<Flow> ac = ArgumentCaptor.forClass(Flow.class);
verify(t, atLeastOnce()).put(eq(LogicalDatastoreType.CONFIGURATION),
- any(InstanceIdentifier.class), ac.capture());
-
+ Matchers.<InstanceIdentifier<Flow>>any(),
+ ac.capture(), anyBoolean());
+
int count = 0;
HashMap<String, FlowCtx> flowMap = new HashMap<>();
for (Flow f : ac.getAllValues()) {
Objects.equals(ep.getAugmentation(OfOverlayContext.class).getNodeConnectorId(),
f.getMatch().getInPort())) {
count += 1;
- assertEquals(FlowUtils.gotoTable((short)(table.getTableId()+1)),
+ assertEquals(FlowUtils.gotoTableInstructions((short)(table.getTableId()+1)),
f.getInstructions());
}
}
assertEquals(1, count);
t = dosync(flowMap);
verify(t, never()).put(any(LogicalDatastoreType.class),
- any(InstanceIdentifier.class),
- any(Flow.class));
+ Matchers.<InstanceIdentifier<Flow>>any(),
+ any(Flow.class), anyBoolean());
}
@Test
public void testL3() throws Exception {
- Endpoint ep = baseEP()
+ Endpoint ep = localEP()
.setL3Address(ImmutableList.of(new L3AddressBuilder()
.setIpAddress(new IpAddress(new Ipv4Address("10.10.10.10")))
.build(),
.build();
endpointManager.addEndpoint(ep);
- ReadWriteTransaction t = dosync(null);
+ ReadWriteTransaction t = dosync(null);
ArgumentCaptor<Flow> ac = ArgumentCaptor.forClass(Flow.class);
verify(t, atLeastOnce()).put(eq(LogicalDatastoreType.CONFIGURATION),
- any(InstanceIdentifier.class), ac.capture());
+ Matchers.<InstanceIdentifier<Flow>>any(),
+ ac.capture(), anyBoolean());
int count = 0;
HashMap<String, FlowCtx> flowMap = new HashMap<>();
Objects.equals(ep.getL3Address().get(1).getIpAddress().getIpv6Address().getValue(),
((Ipv6Match)f.getMatch().getLayer3Match()).getIpv6Source().getValue())))) {
count += 1;
- assertEquals(FlowUtils.gotoTable((short)(table.getTableId()+1)),
+ assertEquals(FlowUtils.gotoTableInstructions((short)(table.getTableId()+1)),
f.getInstructions());
}
}
assertEquals(3, count);
t = dosync(flowMap);
verify(t, never()).put(any(LogicalDatastoreType.class),
- any(InstanceIdentifier.class),
- any(Flow.class));
+ Matchers.<InstanceIdentifier<Flow>>any(),
+ any(Flow.class), anyBoolean());
}
}