Search in sources :

Example 1 with ForwardingObjective

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();
}
Also used : TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 2 with ForwardingObjective

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);
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) RouteEvent(org.onosproject.routeservice.RouteEvent) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) ResolvedRoute(org.onosproject.routeservice.ResolvedRoute) Test(org.junit.Test)

Example 3 with ForwardingObjective

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);
    });
}
Also used : TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 4 with 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);
    });
}
Also used : TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 5 with 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());
}
Also used : NetworkConfigRegistry(org.onosproject.net.config.NetworkConfigRegistry) Dhcp6IaPdOption(org.onlab.packet.dhcp.Dhcp6IaPdOption) DeviceService(org.onosproject.net.device.DeviceService) ARP(org.onlab.packet.ARP) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) InterfaceServiceAdapter(org.onosproject.net.intf.InterfaceServiceAdapter) Pair(org.apache.commons.lang3.tuple.Pair) IgnoreDhcpConfig(org.onosproject.dhcprelay.config.IgnoreDhcpConfig) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) JsonNode(com.fasterxml.jackson.databind.JsonNode) DhcpRelayCounters(org.onosproject.dhcprelay.store.DhcpRelayCounters) Dhcp6IaNaOption(org.onlab.packet.dhcp.Dhcp6IaNaOption) Ip6Address(org.onlab.packet.Ip6Address) DhcpRelayStore(org.onosproject.dhcprelay.store.DhcpRelayStore) Ip4Address(org.onlab.packet.Ip4Address) Set(java.util.Set) StoreDelegate(org.onosproject.store.StoreDelegate) DeviceEvent(org.onosproject.net.device.DeviceEvent) DhcpServerConfig(org.onosproject.dhcprelay.config.DhcpServerConfig) DeviceId(org.onosproject.net.DeviceId) Dictionary(java.util.Dictionary) Pipeliner(org.onosproject.net.behaviour.Pipeliner) Host(org.onosproject.net.Host) ComponentContext(org.osgi.service.component.ComponentContext) HostService(org.onosproject.net.host.HostService) ArrayList(java.util.ArrayList) Dhcp6InterfaceIdOption(org.onlab.packet.dhcp.Dhcp6InterfaceIdOption) DhcpRelayStoreEvent(org.onosproject.dhcprelay.store.DhcpRelayStoreEvent) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DeserializationException(org.onlab.packet.DeserializationException) CircuitId(org.onlab.packet.dhcp.CircuitId) DhcpRelayAgentOption(org.onlab.packet.dhcp.DhcpRelayAgentOption) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Before(org.junit.Before) Charsets(org.apache.commons.io.Charsets) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) Capture(org.easymock.Capture) Resources(com.google.common.io.Resources) VlanId(org.onlab.packet.VlanId) Test(org.junit.Test) IOException(java.io.IOException) EasyMock(org.easymock.EasyMock) Dhcp6IaAddressOption(org.onlab.packet.dhcp.Dhcp6IaAddressOption) IPv6(org.onlab.packet.IPv6) IPv4(org.onlab.packet.IPv4) DHCP6(org.onlab.packet.DHCP6) DhcpRecord(org.onosproject.dhcprelay.store.DhcpRecord) Objective(org.onosproject.net.flowobjective.Objective) MacAddress(org.onlab.packet.MacAddress) Dhcp6Duid(org.onlab.packet.dhcp.Dhcp6Duid) DHCP(org.onlab.packet.DHCP) Assert(org.junit.Assert) DefaultDhcpRelayConfig(org.onosproject.dhcprelay.config.DefaultDhcpRelayConfig) Route(org.onosproject.routeservice.Route) HostLocation(org.onosproject.net.HostLocation) Interface(org.onosproject.net.intf.Interface) TestApplicationId(org.onosproject.TestApplicationId) CoreService(org.onosproject.core.CoreService) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) Dhcp6ClientIdOption(org.onlab.packet.dhcp.Dhcp6ClientIdOption) ByteBuffer(java.nio.ByteBuffer) Ethernet(org.onlab.packet.Ethernet) HostProviderService(org.onosproject.net.host.HostProviderService) Dhcp6IaPrefixOption(org.onlab.packet.dhcp.Dhcp6IaPrefixOption) After(org.junit.After) ImmutableSet(com.google.common.collect.ImmutableSet) Device(org.onosproject.net.Device) Collection(java.util.Collection) PacketProcessor(org.onosproject.net.packet.PacketProcessor) Streams(com.google.common.collect.Streams) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) TestTools.assertAfter(org.onlab.junit.TestTools.assertAfter) IndirectDhcpRelayConfig(org.onosproject.dhcprelay.config.IndirectDhcpRelayConfig) List(java.util.List) InboundPacket(org.onosproject.net.packet.InboundPacket) PacketContext(org.onosproject.net.packet.PacketContext) Optional(java.util.Optional) HostDescription(org.onosproject.net.host.HostDescription) IpPrefix(org.onlab.packet.IpPrefix) PacketContextAdapter(org.onosproject.net.packet.PacketContextAdapter) RouteStoreAdapter(org.onosproject.routeservice.RouteStoreAdapter) Dhcp6RelayOption(org.onlab.packet.dhcp.Dhcp6RelayOption) DhcpRelayCountersStore(org.onosproject.dhcprelay.store.DhcpRelayCountersStore) FlowObjectiveService(org.onosproject.net.flowobjective.FlowObjectiveService) DefaultHost(org.onosproject.net.DefaultHost) ImmutableList(com.google.common.collect.ImmutableList) OutboundPacket(org.onosproject.net.packet.OutboundPacket) PacketServiceAdapter(org.onosproject.net.packet.PacketServiceAdapter) HostId(org.onosproject.net.HostId) DHCP_RELAY_APP(org.onosproject.dhcprelay.DhcpRelayManager.DHCP_RELAY_APP) IpAddress(org.onlab.packet.IpAddress) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Dhcp6Option(org.onlab.packet.dhcp.Dhcp6Option) Maps(com.google.common.collect.Maps) UDP(org.onlab.packet.UDP) DhcpOption(org.onlab.packet.dhcp.DhcpOption) CaptureType(org.easymock.CaptureType) PacketPriority(org.onosproject.net.packet.PacketPriority) IgnoreDhcpConfig(org.onosproject.dhcprelay.config.IgnoreDhcpConfig) Objective(org.onosproject.net.flowobjective.Objective) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) ConnectPoint(org.onosproject.net.ConnectPoint) Test(org.junit.Test)

Aggregations

ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)65 DefaultForwardingObjective (org.onosproject.net.flowobjective.DefaultForwardingObjective)42 TrafficSelector (org.onosproject.net.flow.TrafficSelector)36 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)35 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)28 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)27 Test (org.junit.Test)26 Objective (org.onosproject.net.flowobjective.Objective)26 NextObjective (org.onosproject.net.flowobjective.NextObjective)24 FilteringObjective (org.onosproject.net.flowobjective.FilteringObjective)22 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)12 FlowRule (org.onosproject.net.flow.FlowRule)12 List (java.util.List)11 DeviceId (org.onosproject.net.DeviceId)11 DefaultNextObjective (org.onosproject.net.flowobjective.DefaultNextObjective)11 ObjectiveError (org.onosproject.net.flowobjective.ObjectiveError)11 ImmutableList (com.google.common.collect.ImmutableList)10 PortCriterion (org.onosproject.net.flow.criteria.PortCriterion)9 ObjectiveContext (org.onosproject.net.flowobjective.ObjectiveContext)9 ArrayList (java.util.ArrayList)8