very basic broken reactive forwarding; nit yet using treatments, but rather defa…
…ulting to flood for everything generates a ton of duplicates for now
Showing
10 changed files
with
182 additions
and
17 deletions
1 | +package org.onlab.onos.net.flow; | ||
2 | + | ||
3 | +import static org.slf4j.LoggerFactory.getLogger; | ||
4 | + | ||
5 | +import java.util.Collections; | ||
6 | +import java.util.LinkedList; | ||
7 | +import java.util.List; | ||
8 | + | ||
9 | +import org.onlab.onos.net.PortNumber; | ||
10 | +import org.slf4j.Logger; | ||
11 | + | ||
12 | +@SuppressWarnings("rawtypes") | ||
13 | +public class DefaultTrafficTreatment implements TrafficTreatment { | ||
14 | + | ||
15 | + private final List<Instruction> instructions; | ||
16 | + | ||
17 | + public DefaultTrafficTreatment(List<Instruction> instructions) { | ||
18 | + this.instructions = Collections.unmodifiableList(instructions); | ||
19 | + } | ||
20 | + | ||
21 | + @Override | ||
22 | + public List<Instruction> instructions() { | ||
23 | + return instructions; | ||
24 | + } | ||
25 | + | ||
26 | + /** | ||
27 | + * Builds a list of treatments following the following order. | ||
28 | + * Modifications -> Group -> Output (including drop) | ||
29 | + * | ||
30 | + */ | ||
31 | + | ||
32 | + public static class Builder implements TrafficTreatment.Builder { | ||
33 | + | ||
34 | + private final Logger log = getLogger(getClass()); | ||
35 | + | ||
36 | + List<Instruction<PortNumber>> outputs = new LinkedList<>(); | ||
37 | + | ||
38 | + // TODO: should be a list of instructions based on group objects | ||
39 | + List<Instruction<Object>> groups = new LinkedList<>(); | ||
40 | + | ||
41 | + // TODO: should be a list of instructions based on modification objects | ||
42 | + List<Instruction<Object>> modifications = new LinkedList<>(); | ||
43 | + | ||
44 | + | ||
45 | + @SuppressWarnings("unchecked") | ||
46 | + @Override | ||
47 | + public Builder add(Instruction instruction) { | ||
48 | + switch (instruction.type()) { | ||
49 | + case OUTPUT: | ||
50 | + case DROP: | ||
51 | + // TODO: should check that there is only one drop instruction. | ||
52 | + outputs.add(instruction); | ||
53 | + break; | ||
54 | + case MODIFICATION: | ||
55 | + // TODO: enforce modification order if any | ||
56 | + modifications.add(instruction); | ||
57 | + case GROUP: | ||
58 | + groups.add(instruction); | ||
59 | + default: | ||
60 | + log.warn("Unknown instruction type {}", instruction.type()); | ||
61 | + } | ||
62 | + return this; | ||
63 | + } | ||
64 | + | ||
65 | + @Override | ||
66 | + public TrafficTreatment build() { | ||
67 | + List<Instruction> instructions = new LinkedList<Instruction>(); | ||
68 | + instructions.addAll(modifications); | ||
69 | + instructions.addAll(groups); | ||
70 | + instructions.addAll(outputs); | ||
71 | + | ||
72 | + return new DefaultTrafficTreatment(instructions); | ||
73 | + } | ||
74 | + | ||
75 | + } | ||
76 | + | ||
77 | +} |
... | @@ -2,8 +2,9 @@ package org.onlab.onos.net.flow; | ... | @@ -2,8 +2,9 @@ package org.onlab.onos.net.flow; |
2 | 2 | ||
3 | /** | 3 | /** |
4 | * Abstraction of a single traffic treatment step. | 4 | * Abstraction of a single traffic treatment step. |
5 | + * @param <T> the type parameter for the instruction | ||
5 | */ | 6 | */ |
6 | -public interface Instruction { | 7 | +public interface Instruction<T> { |
7 | 8 | ||
8 | /** | 9 | /** |
9 | * Represents the type of traffic treatment. | 10 | * Represents the type of traffic treatment. |
... | @@ -33,4 +34,17 @@ public interface Instruction { | ... | @@ -33,4 +34,17 @@ public interface Instruction { |
33 | // TODO: Create factory class 'Instructions' that will have various factory | 34 | // TODO: Create factory class 'Instructions' that will have various factory |
34 | // to create specific instructions. | 35 | // to create specific instructions. |
35 | 36 | ||
37 | + /** | ||
38 | + * Returns the type of instruction not to be confused | ||
39 | + * with the instruction's java type. | ||
40 | + * @return type of instruction | ||
41 | + */ | ||
42 | + public Type type(); | ||
43 | + | ||
44 | + /** | ||
45 | + * Returns the actual value of the instruction. | ||
46 | + * @return the value for this instruction | ||
47 | + */ | ||
48 | + public T instruction(); | ||
49 | + | ||
36 | } | 50 | } | ... | ... |
... | @@ -8,8 +8,7 @@ import org.onlab.onos.net.PortNumber; | ... | @@ -8,8 +8,7 @@ import org.onlab.onos.net.PortNumber; |
8 | public final class Instructions { | 8 | public final class Instructions { |
9 | 9 | ||
10 | // Ban construction | 10 | // Ban construction |
11 | - private Instructions() { | 11 | + private Instructions() {} |
12 | - } | ||
13 | 12 | ||
14 | /** | 13 | /** |
15 | * Creates an output instruction using the specified port number. This can | 14 | * Creates an output instruction using the specified port number. This can |
... | @@ -18,8 +17,20 @@ public final class Instructions { | ... | @@ -18,8 +17,20 @@ public final class Instructions { |
18 | * @param number port number | 17 | * @param number port number |
19 | * @return output instruction | 18 | * @return output instruction |
20 | */ | 19 | */ |
21 | - public static Instruction createOutput(PortNumber number) { | 20 | + public static Instruction<PortNumber> createOutput(final PortNumber number) { |
22 | - return null; | 21 | + return new Instruction<PortNumber>() { |
22 | + | ||
23 | + @Override | ||
24 | + public Instruction.Type type() { | ||
25 | + return Type.OUTPUT; | ||
26 | + } | ||
27 | + | ||
28 | + @Override | ||
29 | + public PortNumber instruction() { | ||
30 | + return number; | ||
31 | + } | ||
32 | + | ||
33 | + }; | ||
23 | } | 34 | } |
24 | 35 | ||
25 | // TODO: add create methods | 36 | // TODO: add create methods | ... | ... |
1 | package org.onlab.onos.net.packet; | 1 | package org.onlab.onos.net.packet; |
2 | 2 | ||
3 | -import com.google.common.base.MoreObjects; | 3 | +import java.nio.ByteBuffer; |
4 | + | ||
4 | import org.onlab.onos.net.DeviceId; | 5 | import org.onlab.onos.net.DeviceId; |
5 | import org.onlab.onos.net.flow.TrafficTreatment; | 6 | import org.onlab.onos.net.flow.TrafficTreatment; |
6 | 7 | ||
7 | -import java.nio.ByteBuffer; | 8 | +import com.google.common.base.MoreObjects; |
8 | 9 | ||
9 | /** | 10 | /** |
10 | * Default implementation of an immutable outbound packet. | 11 | * Default implementation of an immutable outbound packet. |
... | @@ -22,7 +23,7 @@ public class DefaultOutboundPacket implements OutboundPacket { | ... | @@ -22,7 +23,7 @@ public class DefaultOutboundPacket implements OutboundPacket { |
22 | * @param data raw packet data | 23 | * @param data raw packet data |
23 | */ | 24 | */ |
24 | public DefaultOutboundPacket(DeviceId sendThrough, | 25 | public DefaultOutboundPacket(DeviceId sendThrough, |
25 | - TrafficTreatment treatment, ByteBuffer data) { | 26 | + TrafficTreatment treatment, ByteBuffer data) { |
26 | this.sendThrough = sendThrough; | 27 | this.sendThrough = sendThrough; |
27 | this.treatment = treatment; | 28 | this.treatment = treatment; |
28 | this.data = data; | 29 | this.data = data; | ... | ... |
1 | package org.onlab.onos.net.packet; | 1 | package org.onlab.onos.net.packet; |
2 | 2 | ||
3 | +import org.onlab.onos.net.flow.DefaultTrafficTreatment; | ||
4 | +import org.onlab.onos.net.flow.TrafficTreatment; | ||
5 | +import org.onlab.onos.net.flow.TrafficTreatment.Builder; | ||
6 | + | ||
3 | 7 | ||
4 | public abstract class DefaultPacketContext implements PacketContext { | 8 | public abstract class DefaultPacketContext implements PacketContext { |
5 | 9 | ||
6 | private final long time; | 10 | private final long time; |
7 | private final InboundPacket inPkt; | 11 | private final InboundPacket inPkt; |
8 | private final OutboundPacket outPkt; | 12 | private final OutboundPacket outPkt; |
13 | + private final TrafficTreatment.Builder builder; | ||
14 | + | ||
9 | private boolean block = false; | 15 | private boolean block = false; |
10 | 16 | ||
17 | + | ||
11 | protected DefaultPacketContext(long time, InboundPacket inPkt, | 18 | protected DefaultPacketContext(long time, InboundPacket inPkt, |
12 | OutboundPacket outPkt, boolean block) { | 19 | OutboundPacket outPkt, boolean block) { |
13 | super(); | 20 | super(); |
... | @@ -15,6 +22,7 @@ public abstract class DefaultPacketContext implements PacketContext { | ... | @@ -15,6 +22,7 @@ public abstract class DefaultPacketContext implements PacketContext { |
15 | this.inPkt = inPkt; | 22 | this.inPkt = inPkt; |
16 | this.outPkt = outPkt; | 23 | this.outPkt = outPkt; |
17 | this.block = block; | 24 | this.block = block; |
25 | + this.builder = new DefaultTrafficTreatment.Builder(); | ||
18 | } | 26 | } |
19 | 27 | ||
20 | @Override | 28 | @Override |
... | @@ -33,6 +41,11 @@ public abstract class DefaultPacketContext implements PacketContext { | ... | @@ -33,6 +41,11 @@ public abstract class DefaultPacketContext implements PacketContext { |
33 | } | 41 | } |
34 | 42 | ||
35 | @Override | 43 | @Override |
44 | + public Builder treatmentBuilder() { | ||
45 | + return builder; | ||
46 | + } | ||
47 | + | ||
48 | + @Override | ||
36 | public abstract void send(); | 49 | public abstract void send(); |
37 | 50 | ||
38 | @Override | 51 | @Override | ... | ... |
... | @@ -2,6 +2,8 @@ package org.onlab.onos.net.trivial.packet.impl; | ... | @@ -2,6 +2,8 @@ package org.onlab.onos.net.trivial.packet.impl; |
2 | 2 | ||
3 | import static org.slf4j.LoggerFactory.getLogger; | 3 | import static org.slf4j.LoggerFactory.getLogger; |
4 | 4 | ||
5 | +import org.onlab.onos.net.PortNumber; | ||
6 | +import org.onlab.onos.net.flow.Instructions; | ||
5 | import org.onlab.onos.net.packet.PacketContext; | 7 | import org.onlab.onos.net.packet.PacketContext; |
6 | import org.onlab.onos.net.packet.PacketProcessor; | 8 | import org.onlab.onos.net.packet.PacketProcessor; |
7 | import org.slf4j.Logger; | 9 | import org.slf4j.Logger; |
... | @@ -12,7 +14,8 @@ public class ReactivePacketProcessor implements PacketProcessor { | ... | @@ -12,7 +14,8 @@ public class ReactivePacketProcessor implements PacketProcessor { |
12 | 14 | ||
13 | @Override | 15 | @Override |
14 | public void process(PacketContext context) { | 16 | public void process(PacketContext context) { |
15 | - log.info("Packet reveived {}", context.inPacket()); | 17 | + context.treatmentBuilder().add(Instructions.createOutput(PortNumber.FLOOD)); |
18 | + context.send(); | ||
16 | } | 19 | } |
17 | 20 | ||
18 | } | 21 | } | ... | ... |
1 | package org.onlab.onos.of.controller; | 1 | package org.onlab.onos.of.controller; |
2 | 2 | ||
3 | +import static org.slf4j.LoggerFactory.getLogger; | ||
4 | + | ||
3 | import java.util.Collections; | 5 | import java.util.Collections; |
4 | 6 | ||
5 | import org.onlab.packet.Ethernet; | 7 | import org.onlab.packet.Ethernet; |
... | @@ -10,9 +12,12 @@ import org.projectfloodlight.openflow.protocol.action.OFActionOutput; | ... | @@ -10,9 +12,12 @@ import org.projectfloodlight.openflow.protocol.action.OFActionOutput; |
10 | import org.projectfloodlight.openflow.protocol.match.MatchField; | 12 | import org.projectfloodlight.openflow.protocol.match.MatchField; |
11 | import org.projectfloodlight.openflow.types.OFBufferId; | 13 | import org.projectfloodlight.openflow.types.OFBufferId; |
12 | import org.projectfloodlight.openflow.types.OFPort; | 14 | import org.projectfloodlight.openflow.types.OFPort; |
15 | +import org.slf4j.Logger; | ||
13 | 16 | ||
14 | public final class DefaultOpenFlowPacketContext implements OpenFlowPacketContext { | 17 | public final class DefaultOpenFlowPacketContext implements OpenFlowPacketContext { |
15 | 18 | ||
19 | + private final Logger log = getLogger(getClass()); | ||
20 | + | ||
16 | private boolean free = true; | 21 | private boolean free = true; |
17 | private boolean isBuilt = false; | 22 | private boolean isBuilt = false; |
18 | private final OpenFlowSwitch sw; | 23 | private final OpenFlowSwitch sw; |
... | @@ -32,8 +37,8 @@ public final class DefaultOpenFlowPacketContext implements OpenFlowPacketContext | ... | @@ -32,8 +37,8 @@ public final class DefaultOpenFlowPacketContext implements OpenFlowPacketContext |
32 | @Override | 37 | @Override |
33 | public void send() { | 38 | public void send() { |
34 | if (free && isBuilt) { | 39 | if (free && isBuilt) { |
35 | - sw.sendMsg(pktout); | ||
36 | block(); | 40 | block(); |
41 | + sw.sendMsg(pktout); | ||
37 | } | 42 | } |
38 | } | 43 | } |
39 | 44 | ... | ... |
... | @@ -15,6 +15,7 @@ import org.apache.felix.scr.annotations.Service; | ... | @@ -15,6 +15,7 @@ import org.apache.felix.scr.annotations.Service; |
15 | import org.onlab.onos.of.controller.DefaultOpenFlowPacketContext; | 15 | import org.onlab.onos.of.controller.DefaultOpenFlowPacketContext; |
16 | import org.onlab.onos.of.controller.Dpid; | 16 | import org.onlab.onos.of.controller.Dpid; |
17 | import org.onlab.onos.of.controller.OpenFlowController; | 17 | import org.onlab.onos.of.controller.OpenFlowController; |
18 | +import org.onlab.onos.of.controller.OpenFlowPacketContext; | ||
18 | import org.onlab.onos.of.controller.OpenFlowSwitch; | 19 | import org.onlab.onos.of.controller.OpenFlowSwitch; |
19 | import org.onlab.onos.of.controller.OpenFlowSwitchListener; | 20 | import org.onlab.onos.of.controller.OpenFlowSwitchListener; |
20 | import org.onlab.onos.of.controller.PacketListener; | 21 | import org.onlab.onos.of.controller.PacketListener; |
... | @@ -106,7 +107,7 @@ public class OpenFlowControllerImpl implements OpenFlowController { | ... | @@ -106,7 +107,7 @@ public class OpenFlowControllerImpl implements OpenFlowController { |
106 | 107 | ||
107 | @Override | 108 | @Override |
108 | public void removePacketListener(PacketListener listener) { | 109 | public void removePacketListener(PacketListener listener) { |
109 | - ofPacketListener.remove(listener); | 110 | + ofPacketListener.values().remove(listener); |
110 | } | 111 | } |
111 | 112 | ||
112 | @Override | 113 | @Override |
... | @@ -123,10 +124,11 @@ public class OpenFlowControllerImpl implements OpenFlowController { | ... | @@ -123,10 +124,11 @@ public class OpenFlowControllerImpl implements OpenFlowController { |
123 | } | 124 | } |
124 | break; | 125 | break; |
125 | case PACKET_IN: | 126 | case PACKET_IN: |
127 | + OpenFlowPacketContext pktCtx = DefaultOpenFlowPacketContext | ||
128 | + .packetContextFromPacketIn(this.getSwitch(dpid), | ||
129 | + (OFPacketIn) msg); | ||
126 | for (PacketListener p : ofPacketListener.values()) { | 130 | for (PacketListener p : ofPacketListener.values()) { |
127 | - p.handlePacket(DefaultOpenFlowPacketContext | 131 | + p.handlePacket(pktCtx); |
128 | - .packetContextFromPacketIn(this.getSwitch(dpid), | ||
129 | - (OFPacketIn) msg)); | ||
130 | } | 132 | } |
131 | break; | 133 | break; |
132 | default: | 134 | default: | ... | ... |
1 | +package org.onlab.onos.provider.of.packet.impl; | ||
2 | + | ||
3 | +import static org.slf4j.LoggerFactory.getLogger; | ||
4 | + | ||
5 | +import org.onlab.onos.net.packet.DefaultPacketContext; | ||
6 | +import org.onlab.onos.net.packet.InboundPacket; | ||
7 | +import org.onlab.onos.net.packet.OutboundPacket; | ||
8 | +import org.onlab.onos.of.controller.OpenFlowPacketContext; | ||
9 | +import org.onlab.packet.Ethernet; | ||
10 | +import org.projectfloodlight.openflow.types.OFPort; | ||
11 | +import org.slf4j.Logger; | ||
12 | + | ||
13 | +public class OpenFlowCorePacketContext extends DefaultPacketContext { | ||
14 | + | ||
15 | + private final Logger log = getLogger(getClass()); | ||
16 | + | ||
17 | + private final OpenFlowPacketContext ofPktCtx; | ||
18 | + | ||
19 | + protected OpenFlowCorePacketContext(long time, InboundPacket inPkt, | ||
20 | + OutboundPacket outPkt, boolean block, OpenFlowPacketContext ofPktCtx) { | ||
21 | + super(time, inPkt, outPkt, block); | ||
22 | + this.ofPktCtx = ofPktCtx; | ||
23 | + } | ||
24 | + | ||
25 | + @Override | ||
26 | + public void send() { | ||
27 | + if (!this.isHandled()) { | ||
28 | + block(); | ||
29 | + if (outPacket() == null) { | ||
30 | + ofPktCtx.build(OFPort.FLOOD); | ||
31 | + } else { | ||
32 | + Ethernet eth = new Ethernet(); | ||
33 | + eth.deserialize(outPacket().data().array(), 0, | ||
34 | + outPacket().data().array().length); | ||
35 | + ofPktCtx.build(eth, OFPort.FLOOD); | ||
36 | + } | ||
37 | + ofPktCtx.send(); | ||
38 | + } | ||
39 | + } | ||
40 | + | ||
41 | +} |
providers/of/packet/src/main/java/org/onlab/onos/provider/of/packet/impl/OpenFlowPacketProvider.java
... | @@ -78,7 +78,6 @@ public class OpenFlowPacketProvider extends AbstractProvider implements PacketPr | ... | @@ -78,7 +78,6 @@ public class OpenFlowPacketProvider extends AbstractProvider implements PacketPr |
78 | */ | 78 | */ |
79 | private class InternalPacketProvider implements PacketListener { | 79 | private class InternalPacketProvider implements PacketListener { |
80 | 80 | ||
81 | - | ||
82 | @Override | 81 | @Override |
83 | public void handlePacket(OpenFlowPacketContext pktCtx) { | 82 | public void handlePacket(OpenFlowPacketContext pktCtx) { |
84 | DeviceId id = DeviceId.deviceId(Dpid.uri(pktCtx.dpid().value())); | 83 | DeviceId id = DeviceId.deviceId(Dpid.uri(pktCtx.dpid().value())); |
... | @@ -88,8 +87,7 @@ public class OpenFlowPacketProvider extends AbstractProvider implements PacketPr | ... | @@ -88,8 +87,7 @@ public class OpenFlowPacketProvider extends AbstractProvider implements PacketPr |
88 | pktCtx.parsed(), ByteBuffer.wrap(pktCtx.unparsed())); | 87 | pktCtx.parsed(), ByteBuffer.wrap(pktCtx.unparsed())); |
89 | 88 | ||
90 | OpenFlowCorePacketContext corePktCtx = | 89 | OpenFlowCorePacketContext corePktCtx = |
91 | - new OpenFlowCorePacketContext(0, inPkt, null, false, pktCtx, | 90 | + new OpenFlowCorePacketContext(0, inPkt, null, false, pktCtx); |
92 | - controller.getSwitch(pktCtx.dpid())); | ||
93 | providerService.processPacket(corePktCtx); | 91 | providerService.processPacket(corePktCtx); |
94 | } | 92 | } |
95 | 93 | ... | ... |
-
Please register or login to post a comment