use of org.onosproject.net.flow.TrafficSelector in project onos by opennetworkinglab.
the class OplinkOpticalUtility method fromFlowRule.
/**
* Transforms a flow FlowRule object to an OplinkCrossConnect object.
* @param behaviour the parent driver handler
* @param rule FlowRule object
* @return cross connect object
*/
public static OplinkCrossConnect fromFlowRule(HandlerBehaviour behaviour, FlowRule rule) {
// TrafficSelector
Set<Criterion> criterions = rule.selector().criteria();
int channel = criterions.stream().filter(c -> c instanceof OchSignalCriterion).map(c -> ((OchSignalCriterion) c).lambda().spacingMultiplier()).findAny().orElse(null);
PortNumber inPort = criterions.stream().filter(c -> c instanceof PortCriterion).map(c -> ((PortCriterion) c).port()).findAny().orElse(null);
// TrafficTreatment
List<Instruction> instructions = rule.treatment().immediate();
PortNumber outPort = instructions.stream().filter(c -> c instanceof Instructions.OutputInstruction).map(c -> ((Instructions.OutputInstruction) c).port()).findAny().orElse(null);
int attenuation = instructions.stream().filter(c -> c instanceof Instructions.ExtensionInstructionWrapper).map(c -> ((Instructions.ExtensionInstructionWrapper) c).extensionInstruction()).filter(c -> c instanceof OplinkAttenuation).map(c -> ((OplinkAttenuation) c).getAttenuation()).findAny().orElse(DEFAULT_ATT);
return new OplinkCrossConnect(inPort, outPort, channel, attenuation);
}
use of org.onosproject.net.flow.TrafficSelector in project onos by opennetworkinglab.
the class DhcpRelayManagerTest method testRemoveIgnoreVlan.
/**
* "IgnoreVlan" policy should be removed when the config removed.
*/
@Test
public void testRemoveIgnoreVlan() {
v4Handler.ignoredVlans.put(DEV_1_ID, IGNORED_VLAN);
v4Handler.ignoredVlans.put(DEV_2_ID, IGNORED_VLAN);
v6Handler.ignoredVlans.put(DEV_1_ID, IGNORED_VLAN);
v6Handler.ignoredVlans.put(DEV_2_ID, IGNORED_VLAN);
IgnoreDhcpConfig config = new IgnoreDhcpConfig();
Capture<Objective> capturedFromDev1 = newCapture(CaptureType.ALL);
flowObjectiveService.apply(eq(DEV_1_ID), capture(capturedFromDev1));
expectLastCall().times(DHCP_SELECTORS.size());
Capture<Objective> capturedFromDev2 = newCapture(CaptureType.ALL);
flowObjectiveService.apply(eq(DEV_2_ID), capture(capturedFromDev2));
expectLastCall().times(DHCP_SELECTORS.size());
replay(flowObjectiveService);
manager.removeConfig(config);
verify(flowObjectiveService);
List<Objective> objectivesFromDev1 = capturedFromDev1.getValues();
List<Objective> objectivesFromDev2 = capturedFromDev2.getValues();
assertTrue(objectivesFromDev1.containsAll(objectivesFromDev2));
assertTrue(objectivesFromDev2.containsAll(objectivesFromDev1));
for (int index = 0; index < objectivesFromDev1.size(); index++) {
TrafficSelector selector = DefaultTrafficSelector.builder(DHCP_SELECTORS.get(index)).matchVlanId(IGNORED_VLAN).build();
ForwardingObjective fwd = (ForwardingObjective) objectivesFromDev1.get(index);
assertEquals(selector, fwd.selector());
assertEquals(DefaultTrafficTreatment.emptyTreatment(), fwd.treatment());
assertEquals(IGNORE_CONTROL_PRIORITY, fwd.priority());
assertEquals(ForwardingObjective.Flag.VERSATILE, fwd.flag());
assertEquals(Objective.Operation.REMOVE, fwd.op());
fwd.context().ifPresent(ctx -> {
ctx.onSuccess(fwd);
});
}
objectivesFromDev2.forEach(obj -> obj.context().ifPresent(ctx -> ctx.onSuccess(obj)));
assertEquals(0, v4Handler.ignoredVlans.size());
assertEquals(0, v6Handler.ignoredVlans.size());
}
use of org.onosproject.net.flow.TrafficSelector in project onos by opennetworkinglab.
the class DhcpRelayManagerTest method testIgnoreVlan.
/**
* Ignores specific vlans from specific devices if config.
*
* @throws Exception the exception from this test
*/
@Test
public void testIgnoreVlan() throws Exception {
ObjectMapper om = new ObjectMapper();
JsonNode json = om.readTree(Resources.getResource(CONFIG_FILE_PATH));
IgnoreDhcpConfig config = new IgnoreDhcpConfig();
json = json.path("apps").path(DHCP_RELAY_APP).path(IgnoreDhcpConfig.KEY);
config.init(APP_ID, IgnoreDhcpConfig.KEY, json, om, null);
Capture<Objective> capturedFromDev1 = newCapture(CaptureType.ALL);
flowObjectiveService.apply(eq(DEV_1_ID), capture(capturedFromDev1));
expectLastCall().times(DHCP_SELECTORS.size());
Capture<Objective> capturedFromDev2 = newCapture(CaptureType.ALL);
flowObjectiveService.apply(eq(DEV_2_ID), capture(capturedFromDev2));
expectLastCall().times(DHCP_SELECTORS.size());
replay(flowObjectiveService);
manager.updateConfig(config);
verify(flowObjectiveService);
List<Objective> objectivesFromDev1 = capturedFromDev1.getValues();
List<Objective> objectivesFromDev2 = capturedFromDev2.getValues();
assertTrue(objectivesFromDev1.containsAll(objectivesFromDev2));
assertTrue(objectivesFromDev2.containsAll(objectivesFromDev1));
for (int index = 0; index < objectivesFromDev1.size(); index++) {
TrafficSelector selector = DefaultTrafficSelector.builder(DHCP_SELECTORS.get(index)).matchVlanId(IGNORED_VLAN).build();
ForwardingObjective fwd = (ForwardingObjective) objectivesFromDev1.get(index);
assertEquals(selector, fwd.selector());
assertEquals(DefaultTrafficTreatment.emptyTreatment(), fwd.treatment());
assertEquals(IGNORE_CONTROL_PRIORITY, fwd.priority());
assertEquals(ForwardingObjective.Flag.VERSATILE, fwd.flag());
assertEquals(Objective.Operation.ADD, fwd.op());
fwd.context().ifPresent(ctx -> {
ctx.onSuccess(fwd);
});
}
objectivesFromDev2.forEach(obj -> obj.context().ifPresent(ctx -> ctx.onSuccess(obj)));
assertEquals(2, v4Handler.ignoredVlans.size());
assertEquals(2, v6Handler.ignoredVlans.size());
}
use of org.onosproject.net.flow.TrafficSelector in project onos by opennetworkinglab.
the class ControlPlaneRedirectManager method updateOspfForwarding.
/**
* Installs or removes OSPF forwarding rules.
*
* @param request provisioning request containing router and interface
* @param install true to create an add objective, false to create a remove
* objective
*/
private void updateOspfForwarding(InterfaceProvisionRequest request, boolean install) {
// TODO IPv6 support has not been implemented yet
Interface intf = request.intf();
log.debug("{} OSPF flows for {}", operation(install), intf);
// OSPF to router
TrafficSelector toSelector = DefaultTrafficSelector.builder().matchInPort(intf.connectPoint().port()).matchEthType(EthType.EtherType.IPV4.ethType().toShort()).matchVlanId(intf.vlan()).matchIPProtocol((byte) OSPF_IP_PROTO).build();
// create nextObjectives for forwarding to the controlPlaneConnectPoint
DeviceId deviceId = intf.connectPoint().deviceId();
PortNumber controlPlanePort = request.controlPlaneConnectPoint().port();
int cpNextId;
if (intf.vlan() == VlanId.NONE) {
cpNextId = modifyNextObjective(deviceId, controlPlanePort, VlanId.vlanId(ASSIGNED_VLAN), true, install);
} else {
cpNextId = modifyNextObjective(deviceId, controlPlanePort, intf.vlan(), false, install);
}
flowObjectiveService.forward(intf.connectPoint().deviceId(), buildForwardingObjective(toSelector, null, cpNextId, install ? request.info().ospfEnabled() : install, ACL_PRIORITY));
}
use of org.onosproject.net.flow.TrafficSelector in project onos by opennetworkinglab.
the class ControlPlaneRedirectManagerTest method setUpInterfaceConfiguration.
/**
* Setting up flowobjective expectations for basic forwarding and ospf.
*/
private void setUpInterfaceConfiguration(Interface intf, boolean install) {
DeviceId deviceId = controlPlaneConnectPoint.deviceId();
PortNumber controlPlanePort = controlPlaneConnectPoint.port();
for (InterfaceIpAddress ip : intf.ipAddressesList()) {
int cpNextId, intfNextId;
cpNextId = modifyNextObjective(deviceId, controlPlanePort, VlanId.vlanId(ControlPlaneRedirectManager.ASSIGNED_VLAN), true, install);
intfNextId = modifyNextObjective(deviceId, intf.connectPoint().port(), VlanId.vlanId(ControlPlaneRedirectManager.ASSIGNED_VLAN), true, install);
// IP to router
TrafficSelector toSelector = buildIPDstSelector(ip.ipAddress().toIpPrefix(), intf.connectPoint().port(), null, intf.mac(), intf.vlan());
flowObjectiveService.forward(deviceId, buildForwardingObjective(toSelector, null, cpNextId, install, ACL_PRIORITY));
expectLastCall().once();
// IP from router
TrafficSelector fromSelector = buildIPSrcSelector(ip.ipAddress().toIpPrefix(), controlPlanePort, intf.mac(), null, intf.vlan());
flowObjectiveService.forward(deviceId, buildForwardingObjective(fromSelector, null, intfNextId, install, ACL_PRIORITY));
expectLastCall().once();
TrafficTreatment puntTreatment = DefaultTrafficTreatment.builder().punt().build();
if (ip.ipAddress().isIp4()) {
// ARP to router
toSelector = buildArpSelector(intf.connectPoint().port(), intf.vlan(), null, null);
flowObjectiveService.forward(deviceId, buildForwardingObjective(toSelector, puntTreatment, cpNextId, install, ACL_PRIORITY + 1));
expectLastCall().once();
// ARP from router
fromSelector = buildArpSelector(controlPlanePort, intf.vlan(), ip.ipAddress().getIp4Address(), intf.mac());
flowObjectiveService.forward(deviceId, buildForwardingObjective(fromSelector, puntTreatment, intfNextId, install, ACL_PRIORITY + 1));
expectLastCall().once();
} else {
// NDP solicitation to router
// Global unicast address
toSelector = buildNdpSelector(intf.connectPoint().port(), intf.vlan(), null, ip.ipAddress().toIpPrefix(), NEIGHBOR_SOLICITATION, null);
flowObjectiveService.forward(deviceId, buildForwardingObjective(toSelector, puntTreatment, cpNextId, install, ACL_PRIORITY + 1));
expectLastCall().once();
// NDP solicitation to router
// Link local address
toSelector = buildNdpSelector(intf.connectPoint().port(), intf.vlan(), null, Ip6Address.valueOf(getLinkLocalAddress(intf.mac().toBytes())).toIpPrefix(), NEIGHBOR_SOLICITATION, null);
flowObjectiveService.forward(deviceId, buildForwardingObjective(toSelector, puntTreatment, cpNextId, install, ACL_PRIORITY + 1));
expectLastCall().once();
// NDP solicitation to router
// solicitated global unicast address
toSelector = buildNdpSelector(intf.connectPoint().port(), intf.vlan(), null, Ip6Address.valueOf(getSolicitNodeAddress(ip.ipAddress().toOctets())).toIpPrefix(), NEIGHBOR_SOLICITATION, null);
flowObjectiveService.forward(deviceId, buildForwardingObjective(toSelector, puntTreatment, cpNextId, install, ACL_PRIORITY + 1));
expectLastCall().once();
// NDP solicitation to router
// solicitated link local address
toSelector = buildNdpSelector(intf.connectPoint().port(), intf.vlan(), null, Ip6Address.valueOf(getSolicitNodeAddress(getLinkLocalAddress(intf.mac().toBytes()))).toIpPrefix(), NEIGHBOR_SOLICITATION, null);
flowObjectiveService.forward(deviceId, buildForwardingObjective(toSelector, puntTreatment, cpNextId, install, ACL_PRIORITY + 1));
expectLastCall().once();
// NDP solicitation from router
// Global unicast address
fromSelector = buildNdpSelector(controlPlanePort, intf.vlan(), ip.ipAddress().toIpPrefix(), null, NEIGHBOR_SOLICITATION, intf.mac());
flowObjectiveService.forward(deviceId, buildForwardingObjective(fromSelector, puntTreatment, intfNextId, install, ACL_PRIORITY + 1));
expectLastCall().once();
// NDP solicitation from router
// Link local address
fromSelector = buildNdpSelector(controlPlanePort, intf.vlan(), Ip6Address.valueOf(getLinkLocalAddress(intf.mac().toBytes())).toIpPrefix(), null, NEIGHBOR_SOLICITATION, intf.mac());
flowObjectiveService.forward(deviceId, buildForwardingObjective(fromSelector, puntTreatment, intfNextId, install, ACL_PRIORITY + 1));
expectLastCall().once();
// NDP advertisement to router
// Global unicast address
toSelector = buildNdpSelector(intf.connectPoint().port(), intf.vlan(), null, ip.ipAddress().toIpPrefix(), NEIGHBOR_ADVERTISEMENT, null);
flowObjectiveService.forward(deviceId, buildForwardingObjective(toSelector, puntTreatment, cpNextId, install, ACL_PRIORITY + 1));
expectLastCall().once();
// NDP advertisement to router
// Link local address
toSelector = buildNdpSelector(intf.connectPoint().port(), intf.vlan(), null, Ip6Address.valueOf(getLinkLocalAddress(intf.mac().toBytes())).toIpPrefix(), NEIGHBOR_ADVERTISEMENT, null);
flowObjectiveService.forward(deviceId, buildForwardingObjective(toSelector, puntTreatment, cpNextId, install, ACL_PRIORITY + 1));
expectLastCall().once();
// NDP advertisement from the router
// Global unicast address
fromSelector = buildNdpSelector(controlPlanePort, intf.vlan(), ip.ipAddress().toIpPrefix(), null, NEIGHBOR_ADVERTISEMENT, null);
flowObjectiveService.forward(deviceId, buildForwardingObjective(fromSelector, puntTreatment, intfNextId, install, ACL_PRIORITY + 1));
expectLastCall().once();
// NDP advertisement from router
// Link local address
fromSelector = buildNdpSelector(controlPlanePort, intf.vlan(), Ip6Address.valueOf(getLinkLocalAddress(intf.mac().toBytes())).toIpPrefix(), null, NEIGHBOR_ADVERTISEMENT, null);
flowObjectiveService.forward(deviceId, buildForwardingObjective(fromSelector, puntTreatment, intfNextId, install, ACL_PRIORITY + 1));
expectLastCall().once();
}
}
// setting expectations for ospf forwarding.
TrafficSelector toSelector = DefaultTrafficSelector.builder().matchInPort(intf.connectPoint().port()).matchEthType(EthType.EtherType.IPV4.ethType().toShort()).matchVlanId(intf.vlan()).matchIPProtocol((byte) OSPF_IP_PROTO).build();
modifyNextObjective(deviceId, controlPlanePort, VlanId.vlanId((short) 4094), true, install);
flowObjectiveService.forward(controlPlaneConnectPoint.deviceId(), buildForwardingObjective(toSelector, null, 1, install, 40001));
expectLastCall().once();
}
Aggregations