Search in sources :

Example 26 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 27 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)

Example 28 with ForwardingObjective

use of org.onosproject.net.flowobjective.ForwardingObjective 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());
}
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) JsonNode(com.fasterxml.jackson.databind.JsonNode) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ConnectPoint(org.onosproject.net.ConnectPoint) Test(org.junit.Test)

Example 29 with ForwardingObjective

use of org.onosproject.net.flowobjective.ForwardingObjective in project onos by opennetworkinglab.

the class ReactiveForwarding method installRule.

// Install a rule forwarding the packet to the specified port.
private void installRule(PacketContext context, PortNumber portNumber, ReactiveForwardMetrics macMetrics) {
    // 
    // We don't support (yet) buffer IDs in the Flow Service so
    // packet out first.
    // 
    Ethernet inPkt = context.inPacket().parsed();
    TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
    // If PacketOutOnly or ARP packet than forward directly to output port
    if (packetOutOnly || inPkt.getEtherType() == Ethernet.TYPE_ARP) {
        packetOut(context, portNumber, macMetrics);
        return;
    }
    // 
    if (matchDstMacOnly) {
        selectorBuilder.matchEthDst(inPkt.getDestinationMAC());
    } else {
        selectorBuilder.matchInPort(context.inPacket().receivedFrom().port()).matchEthSrc(inPkt.getSourceMAC()).matchEthDst(inPkt.getDestinationMAC());
        // If configured Match Vlan ID
        if (matchVlanId && inPkt.getVlanID() != Ethernet.VLAN_UNTAGGED) {
            selectorBuilder.matchVlanId(VlanId.vlanId(inPkt.getVlanID()));
        }
        // 
        if (matchIpv4Address && inPkt.getEtherType() == Ethernet.TYPE_IPV4) {
            IPv4 ipv4Packet = (IPv4) inPkt.getPayload();
            byte ipv4Protocol = ipv4Packet.getProtocol();
            Ip4Prefix matchIp4SrcPrefix = Ip4Prefix.valueOf(ipv4Packet.getSourceAddress(), Ip4Prefix.MAX_MASK_LENGTH);
            Ip4Prefix matchIp4DstPrefix = Ip4Prefix.valueOf(ipv4Packet.getDestinationAddress(), Ip4Prefix.MAX_MASK_LENGTH);
            selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPSrc(matchIp4SrcPrefix).matchIPDst(matchIp4DstPrefix);
            if (matchIpv4Dscp) {
                byte dscp = ipv4Packet.getDscp();
                byte ecn = ipv4Packet.getEcn();
                selectorBuilder.matchIPDscp(dscp).matchIPEcn(ecn);
            }
            if (matchTcpUdpPorts && ipv4Protocol == IPv4.PROTOCOL_TCP) {
                TCP tcpPacket = (TCP) ipv4Packet.getPayload();
                selectorBuilder.matchIPProtocol(ipv4Protocol).matchTcpSrc(TpPort.tpPort(tcpPacket.getSourcePort())).matchTcpDst(TpPort.tpPort(tcpPacket.getDestinationPort()));
            }
            if (matchTcpUdpPorts && ipv4Protocol == IPv4.PROTOCOL_UDP) {
                UDP udpPacket = (UDP) ipv4Packet.getPayload();
                selectorBuilder.matchIPProtocol(ipv4Protocol).matchUdpSrc(TpPort.tpPort(udpPacket.getSourcePort())).matchUdpDst(TpPort.tpPort(udpPacket.getDestinationPort()));
            }
            if (matchIcmpFields && ipv4Protocol == IPv4.PROTOCOL_ICMP) {
                ICMP icmpPacket = (ICMP) ipv4Packet.getPayload();
                selectorBuilder.matchIPProtocol(ipv4Protocol).matchIcmpType(icmpPacket.getIcmpType()).matchIcmpCode(icmpPacket.getIcmpCode());
            }
        }
        // 
        if (matchIpv6Address && inPkt.getEtherType() == Ethernet.TYPE_IPV6) {
            IPv6 ipv6Packet = (IPv6) inPkt.getPayload();
            byte ipv6NextHeader = ipv6Packet.getNextHeader();
            Ip6Prefix matchIp6SrcPrefix = Ip6Prefix.valueOf(ipv6Packet.getSourceAddress(), Ip6Prefix.MAX_MASK_LENGTH);
            Ip6Prefix matchIp6DstPrefix = Ip6Prefix.valueOf(ipv6Packet.getDestinationAddress(), Ip6Prefix.MAX_MASK_LENGTH);
            selectorBuilder.matchEthType(Ethernet.TYPE_IPV6).matchIPv6Src(matchIp6SrcPrefix).matchIPv6Dst(matchIp6DstPrefix);
            if (matchIpv6FlowLabel) {
                selectorBuilder.matchIPv6FlowLabel(ipv6Packet.getFlowLabel());
            }
            if (matchTcpUdpPorts && ipv6NextHeader == IPv6.PROTOCOL_TCP) {
                TCP tcpPacket = (TCP) ipv6Packet.getPayload();
                selectorBuilder.matchIPProtocol(ipv6NextHeader).matchTcpSrc(TpPort.tpPort(tcpPacket.getSourcePort())).matchTcpDst(TpPort.tpPort(tcpPacket.getDestinationPort()));
            }
            if (matchTcpUdpPorts && ipv6NextHeader == IPv6.PROTOCOL_UDP) {
                UDP udpPacket = (UDP) ipv6Packet.getPayload();
                selectorBuilder.matchIPProtocol(ipv6NextHeader).matchUdpSrc(TpPort.tpPort(udpPacket.getSourcePort())).matchUdpDst(TpPort.tpPort(udpPacket.getDestinationPort()));
            }
            if (matchIcmpFields && ipv6NextHeader == IPv6.PROTOCOL_ICMP6) {
                ICMP6 icmp6Packet = (ICMP6) ipv6Packet.getPayload();
                selectorBuilder.matchIPProtocol(ipv6NextHeader).matchIcmpv6Type(icmp6Packet.getIcmpType()).matchIcmpv6Code(icmp6Packet.getIcmpCode());
            }
        }
    }
    TrafficTreatment treatment;
    if (inheritFlowTreatment) {
        treatment = context.treatmentBuilder().setOutput(portNumber).build();
    } else {
        treatment = DefaultTrafficTreatment.builder().setOutput(portNumber).build();
    }
    ForwardingObjective forwardingObjective = DefaultForwardingObjective.builder().withSelector(selectorBuilder.build()).withTreatment(treatment).withPriority(flowPriority).withFlag(ForwardingObjective.Flag.VERSATILE).fromApp(appId).makeTemporary(flowTimeout).add();
    flowObjectiveService.forward(context.inPacket().receivedFrom().deviceId(), forwardingObjective);
    forwardPacket(macMetrics);
    // 
    if (packetOutOfppTable) {
        packetOut(context, PortNumber.TABLE, macMetrics);
    } else {
        packetOut(context, portNumber, macMetrics);
    }
}
Also used : TCP(org.onlab.packet.TCP) UDP(org.onlab.packet.UDP) IPv6(org.onlab.packet.IPv6) IPv4(org.onlab.packet.IPv4) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Ip6Prefix(org.onlab.packet.Ip6Prefix) Ethernet(org.onlab.packet.Ethernet) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Ip4Prefix(org.onlab.packet.Ip4Prefix) ICMP6(org.onlab.packet.ICMP6) ICMP(org.onlab.packet.ICMP)

Example 30 with ForwardingObjective

use of org.onosproject.net.flowobjective.ForwardingObjective in project TFG by mattinelorza.

the class PipelinerImpl method forward.

@Override
public void forward(ForwardingObjective obj) {
    if (obj.treatment() == null) {
        obj.context().ifPresent(c -> c.onError(obj, ObjectiveError.UNSUPPORTED));
    }
    // Whether this objective specifies an OUTPUT:CONTROLLER instruction.
    final boolean hasCloneToCpuAction = obj.treatment().allInstructions().stream().filter(i -> i.type().equals(OUTPUT)).map(i -> (Instructions.OutputInstruction) i).anyMatch(i -> i.port().equals(PortNumber.CONTROLLER));
    if (!hasCloneToCpuAction) {
        // We support only objectives for clone to CPU behaviours (e.g. for
        // host and link discovery)
        obj.context().ifPresent(c -> c.onError(obj, ObjectiveError.UNSUPPORTED));
    }
    // Create an equivalent FlowRule with same selector and clone_to_cpu action.
    final PiAction cloneToCpuAction = PiAction.builder().withId(PiActionId.of(CLONE_TO_CPU)).build();
    final FlowRule.Builder ruleBuilder = DefaultFlowRule.builder().forTable(PiTableId.of(ACL_TABLE)).forDevice(deviceId).withSelector(obj.selector()).fromApp(obj.appId()).withPriority(obj.priority()).withTreatment(DefaultTrafficTreatment.builder().piTableAction(cloneToCpuAction).build());
    if (obj.permanent()) {
        ruleBuilder.makePermanent();
    } else {
        ruleBuilder.makeTemporary(obj.timeout());
    }
    final GroupDescription cloneGroup = Utils.buildCloneGroup(obj.appId(), deviceId, CPU_CLONE_SESSION_ID, // Just controller in this case.
    Collections.singleton(PortNumber.CONTROLLER));
    switch(obj.op()) {
        case ADD:
            flowRuleService.applyFlowRules(ruleBuilder.build());
            groupService.addGroup(cloneGroup);
            break;
        case REMOVE:
            flowRuleService.removeFlowRules(ruleBuilder.build());
            // pointing to it.
            break;
        default:
            log.warn("Unknown operation {}", obj.op());
    }
    obj.context().ifPresent(c -> c.onSuccess(obj));
}
Also used : PiTableId(org.onosproject.net.pi.model.PiTableId) Pipeliner(org.onosproject.net.behaviour.Pipeliner) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) PortNumber(org.onosproject.net.PortNumber) NextGroup(org.onosproject.net.behaviour.NextGroup) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError) FlowRuleService(org.onosproject.net.flow.FlowRuleService) NextObjective(org.onosproject.net.flowobjective.NextObjective) Utils(org.onosproject.ngsdn.tutorial.common.Utils) PipelinerContext(org.onosproject.net.behaviour.PipelinerContext) Instructions(org.onosproject.net.flow.instructions.Instructions) Logger(org.slf4j.Logger) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) GroupService(org.onosproject.net.group.GroupService) PiAction(org.onosproject.net.pi.runtime.PiAction) List(java.util.List) FlowRule(org.onosproject.net.flow.FlowRule) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) DeviceId(org.onosproject.net.DeviceId) CPU_CLONE_SESSION_ID(org.onosproject.ngsdn.tutorial.AppConstants.CPU_CLONE_SESSION_ID) GroupDescription(org.onosproject.net.group.GroupDescription) Collections(java.util.Collections) OUTPUT(org.onosproject.net.flow.instructions.Instruction.Type.OUTPUT) PiActionId(org.onosproject.net.pi.model.PiActionId) GroupDescription(org.onosproject.net.group.GroupDescription) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) PiAction(org.onosproject.net.pi.runtime.PiAction)

Aggregations

ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)88 DefaultForwardingObjective (org.onosproject.net.flowobjective.DefaultForwardingObjective)57 TrafficSelector (org.onosproject.net.flow.TrafficSelector)50 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)48 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)38 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)37 Test (org.junit.Test)33 NextObjective (org.onosproject.net.flowobjective.NextObjective)32 Objective (org.onosproject.net.flowobjective.Objective)32 FilteringObjective (org.onosproject.net.flowobjective.FilteringObjective)28 List (java.util.List)24 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)20 FlowRule (org.onosproject.net.flow.FlowRule)20 DeviceId (org.onosproject.net.DeviceId)18 ObjectiveContext (org.onosproject.net.flowobjective.ObjectiveContext)18 ObjectiveError (org.onosproject.net.flowobjective.ObjectiveError)16 DefaultNextObjective (org.onosproject.net.flowobjective.DefaultNextObjective)15 GroupDescription (org.onosproject.net.group.GroupDescription)15 PiAction (org.onosproject.net.pi.runtime.PiAction)14 ArrayList (java.util.ArrayList)13