use of org.onosproject.net.flowobjective.ForwardingObjective in project onos by opennetworkinglab.
the class FibInstallerTest method createForwardingObjective.
/**
* Creates a new forwarding objective with the given parameters.
*
* @param prefix IP prefix
* @param add whether to create an add objective or a remove objective
* @return new forwarding objective
*/
private ForwardingObjective createForwardingObjective(IpPrefix prefix, boolean add) {
TrafficSelector selector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPDst(prefix).build();
int priority = prefix.prefixLength() * 5 + 100;
ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective.builder().fromApp(APPID).makePermanent().withSelector(selector).withPriority(priority).withFlag(ForwardingObjective.Flag.SPECIFIC);
if (add) {
fwdBuilder.nextStep(NEXT_ID);
} else {
fwdBuilder.withTreatment(DefaultTrafficTreatment.builder().build());
}
return add ? fwdBuilder.add() : fwdBuilder.remove();
}
use of org.onosproject.net.flowobjective.ForwardingObjective in project onos by opennetworkinglab.
the class FibInstallerTest method testRouteUpdate.
/**
* Tests updating a route.
*
* We verify that the flowObjectiveService records the correct state and that the
* correct flow is submitted to the flowObjectiveService.
*/
@Test
public void testRouteUpdate() {
// Firstly add a route
testRouteAdd();
reset(flowObjectiveService);
ResolvedRoute oldRoute = createRoute(PREFIX1, NEXT_HOP1, MAC1);
ResolvedRoute route = createRoute(PREFIX1, NEXT_HOP2, MAC2);
// Create the next objective
NextObjective nextObjective = createNextObjective(MAC2, MAC2, SW1_ETH2.port(), VLAN1, true);
flowObjectiveService.next(DEVICE_ID, nextObjective);
// Create the flow objective
ForwardingObjective fwd = createForwardingObjective(PREFIX1, true);
flowObjectiveService.forward(DEVICE_ID, fwd);
EasyMock.expectLastCall().once();
setUpFlowObjectiveService();
// Send in the update event
routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_UPDATED, route, oldRoute));
verify(flowObjectiveService);
}
use of org.onosproject.net.flowobjective.ForwardingObjective in project onos by opennetworkinglab.
the class ArtemisDeaggregatorImpl method installClientRules.
/**
* Rules to be installed on MOAS Client.
*/
private void installClientRules() {
log.info("installClientRules");
artemisService.getConfig().ifPresent(config -> {
// selector
TrafficSelector selector = DefaultTrafficSelector.builder().matchEthType(TYPE_IPV4).matchIPSrc(remoteTunnelIp.toIpPrefix()).matchIPDst(config.moasInfo().getTunnelPoint().getLocalIp().toIpPrefix()).build();
// treatment
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(PortNumber.LOCAL).build();
// forwarding objective builder
ForwardingObjective forwardingObjective = DefaultForwardingObjective.builder().withSelector(selector).withTreatment(treatment).withPriority(PRIORITY).withFlag(ForwardingObjective.Flag.VERSATILE).fromApp(appId).add();
// send flow objective to specified switch
flowObjectiveService.forward(DeviceId.deviceId(tunnelPort.element().id().toString()), forwardingObjective);
log.info("Installing flow rule = {}", forwardingObjective);
});
}
use of org.onosproject.net.flowobjective.ForwardingObjective in project onos by opennetworkinglab.
the class ArtemisDeaggregatorImpl method installServerRules.
/**
* Rules to be isntalled on MOAS Server.
*/
private void installServerRules() {
log.info("installServerRules");
artemisService.getConfig().ifPresent(config -> {
// selector
TrafficSelector selector = DefaultTrafficSelector.builder().matchEthType(TYPE_IPV4).matchIPDst(remotePrefix).build();
// treatment
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(tunnelPort.number()).build();
// forwarding objective builder
ForwardingObjective forwardingObjective = DefaultForwardingObjective.builder().withSelector(selector).withTreatment(treatment).withPriority(PRIORITY).withFlag(ForwardingObjective.Flag.VERSATILE).fromApp(appId).add();
// send flow objective to specified switch
flowObjectiveService.forward(DeviceId.deviceId(tunnelPort.element().id().toString()), forwardingObjective);
log.info("Installing flow rule = {}", forwardingObjective);
// selector
selector = DefaultTrafficSelector.builder().matchEthType(TYPE_IPV4).matchIPSrc(config.moasInfo().getTunnelPoint().getLocalIp().toIpPrefix()).matchIPDst(remoteTunnelIp.toIpPrefix()).build();
// treatment
treatment = DefaultTrafficTreatment.builder().setOutput(PortNumber.portNumber(2)).build();
// forwarding objective builder
forwardingObjective = DefaultForwardingObjective.builder().withSelector(selector).withTreatment(treatment).withPriority(PRIORITY).withFlag(ForwardingObjective.Flag.VERSATILE).fromApp(appId).add();
// send flow objective to specified switch
flowObjectiveService.forward(DeviceId.deviceId(tunnelPort.element().id().toString()), forwardingObjective);
log.info("Installing flow rule = {}", forwardingObjective);
});
}
use of org.onosproject.net.flowobjective.ForwardingObjective 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());
}
Aggregations