Move reactive forwarding to flow objectives
Change-Id: I8c77e5e04d7d7a4480dbff47578ef46aa7637054
Showing
1 changed file
with
35 additions
and
25 deletions
... | @@ -39,13 +39,14 @@ import org.onosproject.net.Host; | ... | @@ -39,13 +39,14 @@ import org.onosproject.net.Host; |
39 | import org.onosproject.net.HostId; | 39 | import org.onosproject.net.HostId; |
40 | import org.onosproject.net.Path; | 40 | import org.onosproject.net.Path; |
41 | import org.onosproject.net.PortNumber; | 41 | import org.onosproject.net.PortNumber; |
42 | -import org.onosproject.net.flow.DefaultFlowRule; | ||
43 | import org.onosproject.net.flow.DefaultTrafficSelector; | 42 | import org.onosproject.net.flow.DefaultTrafficSelector; |
44 | import org.onosproject.net.flow.DefaultTrafficTreatment; | 43 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
45 | -import org.onosproject.net.flow.FlowRule; | ||
46 | import org.onosproject.net.flow.FlowRuleService; | 44 | import org.onosproject.net.flow.FlowRuleService; |
47 | import org.onosproject.net.flow.TrafficSelector; | 45 | import org.onosproject.net.flow.TrafficSelector; |
48 | import org.onosproject.net.flow.TrafficTreatment; | 46 | import org.onosproject.net.flow.TrafficTreatment; |
47 | +import org.onosproject.net.flowobjective.DefaultForwardingObjective; | ||
48 | +import org.onosproject.net.flowobjective.FlowObjectiveService; | ||
49 | +import org.onosproject.net.flowobjective.ForwardingObjective; | ||
49 | import org.onosproject.net.host.HostService; | 50 | import org.onosproject.net.host.HostService; |
50 | import org.onosproject.net.packet.InboundPacket; | 51 | import org.onosproject.net.packet.InboundPacket; |
51 | import org.onosproject.net.packet.PacketContext; | 52 | import org.onosproject.net.packet.PacketContext; |
... | @@ -86,6 +87,9 @@ public class ReactiveForwarding { | ... | @@ -86,6 +87,9 @@ public class ReactiveForwarding { |
86 | protected FlowRuleService flowRuleService; | 87 | protected FlowRuleService flowRuleService; |
87 | 88 | ||
88 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 89 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
90 | + protected FlowObjectiveService flowObjectiveService; | ||
91 | + | ||
92 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
89 | protected CoreService coreService; | 93 | protected CoreService coreService; |
90 | 94 | ||
91 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 95 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
... | @@ -466,7 +470,7 @@ public class ReactiveForwarding { | ... | @@ -466,7 +470,7 @@ public class ReactiveForwarding { |
466 | // packet out first. | 470 | // packet out first. |
467 | // | 471 | // |
468 | Ethernet inPkt = context.inPacket().parsed(); | 472 | Ethernet inPkt = context.inPacket().parsed(); |
469 | - TrafficSelector.Builder builder = DefaultTrafficSelector.builder(); | 473 | + TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(); |
470 | 474 | ||
471 | // If PacketOutOnly or ARP packet than forward directly to output port | 475 | // If PacketOutOnly or ARP packet than forward directly to output port |
472 | if (packetOutOnly || inPkt.getEtherType() == Ethernet.TYPE_ARP) { | 476 | if (packetOutOnly || inPkt.getEtherType() == Ethernet.TYPE_ARP) { |
... | @@ -481,15 +485,15 @@ public class ReactiveForwarding { | ... | @@ -481,15 +485,15 @@ public class ReactiveForwarding { |
481 | // Create flows with default matching and include configured fields | 485 | // Create flows with default matching and include configured fields |
482 | // | 486 | // |
483 | if (matchDstMacOnly) { | 487 | if (matchDstMacOnly) { |
484 | - builder.matchEthDst(inPkt.getDestinationMAC()); | 488 | + selectorBuilder.matchEthDst(inPkt.getDestinationMAC()); |
485 | } else { | 489 | } else { |
486 | - builder.matchInPort(context.inPacket().receivedFrom().port()) | 490 | + selectorBuilder.matchInPort(context.inPacket().receivedFrom().port()) |
487 | .matchEthSrc(inPkt.getSourceMAC()) | 491 | .matchEthSrc(inPkt.getSourceMAC()) |
488 | .matchEthDst(inPkt.getDestinationMAC()); | 492 | .matchEthDst(inPkt.getDestinationMAC()); |
489 | 493 | ||
490 | // If configured Match Vlan ID | 494 | // If configured Match Vlan ID |
491 | if (matchVlanId && inPkt.getVlanID() != Ethernet.VLAN_UNTAGGED) { | 495 | if (matchVlanId && inPkt.getVlanID() != Ethernet.VLAN_UNTAGGED) { |
492 | - builder.matchVlanId(VlanId.vlanId(inPkt.getVlanID())); | 496 | + selectorBuilder.matchVlanId(VlanId.vlanId(inPkt.getVlanID())); |
493 | } | 497 | } |
494 | 498 | ||
495 | // | 499 | // |
... | @@ -505,31 +509,31 @@ public class ReactiveForwarding { | ... | @@ -505,31 +509,31 @@ public class ReactiveForwarding { |
505 | Ip4Prefix matchIp4DstPrefix = | 509 | Ip4Prefix matchIp4DstPrefix = |
506 | Ip4Prefix.valueOf(ipv4Packet.getDestinationAddress(), | 510 | Ip4Prefix.valueOf(ipv4Packet.getDestinationAddress(), |
507 | Ip4Prefix.MAX_MASK_LENGTH); | 511 | Ip4Prefix.MAX_MASK_LENGTH); |
508 | - builder.matchEthType(inPkt.getEtherType()) | 512 | + selectorBuilder.matchEthType(inPkt.getEtherType()) |
509 | .matchIPSrc(matchIp4SrcPrefix) | 513 | .matchIPSrc(matchIp4SrcPrefix) |
510 | .matchIPDst(matchIp4DstPrefix); | 514 | .matchIPDst(matchIp4DstPrefix); |
511 | 515 | ||
512 | if (matchIpv4Dscp) { | 516 | if (matchIpv4Dscp) { |
513 | byte dscp = ipv4Packet.getDscp(); | 517 | byte dscp = ipv4Packet.getDscp(); |
514 | byte ecn = ipv4Packet.getEcn(); | 518 | byte ecn = ipv4Packet.getEcn(); |
515 | - builder.matchIPDscp(dscp).matchIPEcn(ecn); | 519 | + selectorBuilder.matchIPDscp(dscp).matchIPEcn(ecn); |
516 | } | 520 | } |
517 | 521 | ||
518 | if (matchTcpUdpPorts && ipv4Protocol == IPv4.PROTOCOL_TCP) { | 522 | if (matchTcpUdpPorts && ipv4Protocol == IPv4.PROTOCOL_TCP) { |
519 | TCP tcpPacket = (TCP) ipv4Packet.getPayload(); | 523 | TCP tcpPacket = (TCP) ipv4Packet.getPayload(); |
520 | - builder.matchIPProtocol(ipv4Protocol) | 524 | + selectorBuilder.matchIPProtocol(ipv4Protocol) |
521 | .matchTcpSrc(tcpPacket.getSourcePort()) | 525 | .matchTcpSrc(tcpPacket.getSourcePort()) |
522 | .matchTcpDst(tcpPacket.getDestinationPort()); | 526 | .matchTcpDst(tcpPacket.getDestinationPort()); |
523 | } | 527 | } |
524 | if (matchTcpUdpPorts && ipv4Protocol == IPv4.PROTOCOL_UDP) { | 528 | if (matchTcpUdpPorts && ipv4Protocol == IPv4.PROTOCOL_UDP) { |
525 | UDP udpPacket = (UDP) ipv4Packet.getPayload(); | 529 | UDP udpPacket = (UDP) ipv4Packet.getPayload(); |
526 | - builder.matchIPProtocol(ipv4Protocol) | 530 | + selectorBuilder.matchIPProtocol(ipv4Protocol) |
527 | .matchUdpSrc(udpPacket.getSourcePort()) | 531 | .matchUdpSrc(udpPacket.getSourcePort()) |
528 | .matchUdpDst(udpPacket.getDestinationPort()); | 532 | .matchUdpDst(udpPacket.getDestinationPort()); |
529 | } | 533 | } |
530 | if (matchIcmpFields && ipv4Protocol == IPv4.PROTOCOL_ICMP) { | 534 | if (matchIcmpFields && ipv4Protocol == IPv4.PROTOCOL_ICMP) { |
531 | ICMP icmpPacket = (ICMP) ipv4Packet.getPayload(); | 535 | ICMP icmpPacket = (ICMP) ipv4Packet.getPayload(); |
532 | - builder.matchIPProtocol(ipv4Protocol) | 536 | + selectorBuilder.matchIPProtocol(ipv4Protocol) |
533 | .matchIcmpType(icmpPacket.getIcmpType()) | 537 | .matchIcmpType(icmpPacket.getIcmpType()) |
534 | .matchIcmpCode(icmpPacket.getIcmpCode()); | 538 | .matchIcmpCode(icmpPacket.getIcmpCode()); |
535 | } | 539 | } |
... | @@ -548,42 +552,48 @@ public class ReactiveForwarding { | ... | @@ -548,42 +552,48 @@ public class ReactiveForwarding { |
548 | Ip6Prefix matchIp6DstPrefix = | 552 | Ip6Prefix matchIp6DstPrefix = |
549 | Ip6Prefix.valueOf(ipv6Packet.getDestinationAddress(), | 553 | Ip6Prefix.valueOf(ipv6Packet.getDestinationAddress(), |
550 | Ip6Prefix.MAX_MASK_LENGTH); | 554 | Ip6Prefix.MAX_MASK_LENGTH); |
551 | - builder.matchIPv6Src(matchIp6SrcPrefix) | 555 | + selectorBuilder.matchIPv6Src(matchIp6SrcPrefix) |
552 | .matchIPv6Dst(matchIp6DstPrefix); | 556 | .matchIPv6Dst(matchIp6DstPrefix); |
553 | 557 | ||
554 | if (matchIpv6FlowLabel) { | 558 | if (matchIpv6FlowLabel) { |
555 | - builder.matchIPv6FlowLabel(ipv6Packet.getFlowLabel()); | 559 | + selectorBuilder.matchIPv6FlowLabel(ipv6Packet.getFlowLabel()); |
556 | } | 560 | } |
557 | 561 | ||
558 | if (matchTcpUdpPorts && ipv6NextHeader == IPv6.PROTOCOL_TCP) { | 562 | if (matchTcpUdpPorts && ipv6NextHeader == IPv6.PROTOCOL_TCP) { |
559 | TCP tcpPacket = (TCP) ipv6Packet.getPayload(); | 563 | TCP tcpPacket = (TCP) ipv6Packet.getPayload(); |
560 | - builder.matchIPProtocol(ipv6NextHeader) | 564 | + selectorBuilder.matchIPProtocol(ipv6NextHeader) |
561 | .matchTcpSrc(tcpPacket.getSourcePort()) | 565 | .matchTcpSrc(tcpPacket.getSourcePort()) |
562 | .matchTcpDst(tcpPacket.getDestinationPort()); | 566 | .matchTcpDst(tcpPacket.getDestinationPort()); |
563 | } | 567 | } |
564 | if (matchTcpUdpPorts && ipv6NextHeader == IPv6.PROTOCOL_UDP) { | 568 | if (matchTcpUdpPorts && ipv6NextHeader == IPv6.PROTOCOL_UDP) { |
565 | UDP udpPacket = (UDP) ipv6Packet.getPayload(); | 569 | UDP udpPacket = (UDP) ipv6Packet.getPayload(); |
566 | - builder.matchIPProtocol(ipv6NextHeader) | 570 | + selectorBuilder.matchIPProtocol(ipv6NextHeader) |
567 | .matchUdpSrc(udpPacket.getSourcePort()) | 571 | .matchUdpSrc(udpPacket.getSourcePort()) |
568 | .matchUdpDst(udpPacket.getDestinationPort()); | 572 | .matchUdpDst(udpPacket.getDestinationPort()); |
569 | } | 573 | } |
570 | if (matchIcmpFields && ipv6NextHeader == IPv6.PROTOCOL_ICMP6) { | 574 | if (matchIcmpFields && ipv6NextHeader == IPv6.PROTOCOL_ICMP6) { |
571 | ICMP6 icmp6Packet = (ICMP6) ipv6Packet.getPayload(); | 575 | ICMP6 icmp6Packet = (ICMP6) ipv6Packet.getPayload(); |
572 | - builder.matchIPProtocol(ipv6NextHeader) | 576 | + selectorBuilder.matchIPProtocol(ipv6NextHeader) |
573 | .matchIcmpv6Type(icmp6Packet.getIcmpType()) | 577 | .matchIcmpv6Type(icmp6Packet.getIcmpType()) |
574 | .matchIcmpv6Code(icmp6Packet.getIcmpCode()); | 578 | .matchIcmpv6Code(icmp6Packet.getIcmpCode()); |
575 | } | 579 | } |
576 | } | 580 | } |
577 | } | 581 | } |
578 | - TrafficTreatment.Builder treat = DefaultTrafficTreatment.builder(); | 582 | + TrafficTreatment treatment = DefaultTrafficTreatment.builder() |
579 | - treat.setOutput(portNumber); | 583 | + .setOutput(portNumber) |
580 | - | 584 | + .build(); |
581 | - FlowRule f = | 585 | + |
582 | - new DefaultFlowRule(context.inPacket().receivedFrom().deviceId(), | 586 | + ForwardingObjective forwardingObjective = DefaultForwardingObjective.builder() |
583 | - builder.build(), treat.build(), flowPriority, | 587 | + .withSelector(selectorBuilder.build()) |
584 | - appId, flowTimeout, false); | 588 | + .withTreatment(treatment) |
585 | - | 589 | + .withPriority(flowPriority) |
586 | - flowRuleService.applyFlowRules(f); | 590 | + .withFlag(ForwardingObjective.Flag.VERSATILE) |
591 | + .fromApp(appId) | ||
592 | + .makeTemporary(flowTimeout) | ||
593 | + .add(); | ||
594 | + | ||
595 | + flowObjectiveService.forward(context.inPacket().receivedFrom().deviceId(), | ||
596 | + forwardingObjective); | ||
587 | 597 | ||
588 | // | 598 | // |
589 | // If packetOutOfppTable | 599 | // If packetOutOfppTable | ... | ... |
-
Please register or login to post a comment