Showing
5 changed files
with
34 additions
and
17 deletions
... | @@ -2,7 +2,8 @@ package org.onlab.onos.net.trivial.packet.impl; | ... | @@ -2,7 +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 java.util.ArrayList; | 5 | +import java.util.Map; |
6 | +import java.util.TreeMap; | ||
6 | 7 | ||
7 | import org.apache.felix.scr.annotations.Activate; | 8 | import org.apache.felix.scr.annotations.Activate; |
8 | import org.apache.felix.scr.annotations.Component; | 9 | import org.apache.felix.scr.annotations.Component; |
... | @@ -39,7 +40,7 @@ implements PacketService, PacketProviderRegistry { | ... | @@ -39,7 +40,7 @@ implements PacketService, PacketProviderRegistry { |
39 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 40 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
40 | private DeviceService deviceService; | 41 | private DeviceService deviceService; |
41 | 42 | ||
42 | - private final ArrayList<PacketProcessor> processors = new ArrayList<>(); | 43 | + private final Map<Integer, PacketProcessor> processors = new TreeMap<>(); |
43 | 44 | ||
44 | private final PacketProcessor reactiveProcessor = new ReactivePacketProcessor(); | 45 | private final PacketProcessor reactiveProcessor = new ReactivePacketProcessor(); |
45 | 46 | ||
... | @@ -57,12 +58,12 @@ implements PacketService, PacketProviderRegistry { | ... | @@ -57,12 +58,12 @@ implements PacketService, PacketProviderRegistry { |
57 | 58 | ||
58 | @Override | 59 | @Override |
59 | public void addProcessor(PacketProcessor processor, int priority) { | 60 | public void addProcessor(PacketProcessor processor, int priority) { |
60 | - processors.add(priority, processor); | 61 | + processors.put(priority, processor); |
61 | } | 62 | } |
62 | 63 | ||
63 | @Override | 64 | @Override |
64 | public void removeProcessor(PacketProcessor processor) { | 65 | public void removeProcessor(PacketProcessor processor) { |
65 | - processors.remove(processor); | 66 | + processors.values().remove(processor); |
66 | } | 67 | } |
67 | 68 | ||
68 | @Override | 69 | @Override |
... | @@ -89,7 +90,7 @@ implements PacketService, PacketProviderRegistry { | ... | @@ -89,7 +90,7 @@ implements PacketService, PacketProviderRegistry { |
89 | 90 | ||
90 | @Override | 91 | @Override |
91 | public void processPacket(PacketContext context) { | 92 | public void processPacket(PacketContext context) { |
92 | - for (PacketProcessor processor : processors) { | 93 | + for (PacketProcessor processor : processors.values()) { |
93 | processor.process(context); | 94 | processor.process(context); |
94 | } | 95 | } |
95 | } | 96 | } | ... | ... |
... | @@ -68,6 +68,8 @@ | ... | @@ -68,6 +68,8 @@ |
68 | <bundle>mvn:org.onlab.onos/onos-of-provider-device/1.0.0-SNAPSHOT</bundle> | 68 | <bundle>mvn:org.onlab.onos/onos-of-provider-device/1.0.0-SNAPSHOT</bundle> |
69 | <bundle>mvn:org.onlab.onos/onos-of-provider-link/1.0.0-SNAPSHOT</bundle> | 69 | <bundle>mvn:org.onlab.onos/onos-of-provider-link/1.0.0-SNAPSHOT</bundle> |
70 | <bundle>mvn:org.onlab.onos/onos-of-provider-host/1.0.0-SNAPSHOT</bundle> | 70 | <bundle>mvn:org.onlab.onos/onos-of-provider-host/1.0.0-SNAPSHOT</bundle> |
71 | + <bundle>mvn:org.onlab.onos/onos-of-provider-packet/1.0.0-SNAPSHOT</bundle> | ||
72 | + | ||
71 | </feature> | 73 | </feature> |
72 | 74 | ||
73 | <feature name="onos-app-tvue" version="1.0.0" | 75 | <feature name="onos-app-tvue" version="1.0.0" | ... | ... |
... | @@ -33,8 +33,8 @@ public final class DefaultOpenFlowPacketContext implements OpenFlowPacketContext | ... | @@ -33,8 +33,8 @@ public final class DefaultOpenFlowPacketContext implements OpenFlowPacketContext |
33 | public void send() { | 33 | public void send() { |
34 | if (free && isBuilt) { | 34 | if (free && isBuilt) { |
35 | sw.sendMsg(pktout); | 35 | sw.sendMsg(pktout); |
36 | + block(); | ||
36 | } | 37 | } |
37 | - | ||
38 | } | 38 | } |
39 | 39 | ||
40 | @Override | 40 | @Override | ... | ... |
1 | package org.onlab.onos.of.controller.impl; | 1 | package org.onlab.onos.of.controller.impl; |
2 | 2 | ||
3 | -import java.util.ArrayList; | ||
4 | import java.util.HashSet; | 3 | import java.util.HashSet; |
5 | -import java.util.List; | 4 | +import java.util.Map; |
6 | import java.util.Set; | 5 | import java.util.Set; |
6 | +import java.util.TreeMap; | ||
7 | import java.util.concurrent.ConcurrentHashMap; | 7 | import java.util.concurrent.ConcurrentHashMap; |
8 | import java.util.concurrent.locks.Lock; | 8 | import java.util.concurrent.locks.Lock; |
9 | import java.util.concurrent.locks.ReentrantLock; | 9 | import java.util.concurrent.locks.ReentrantLock; |
... | @@ -43,7 +43,7 @@ public class OpenFlowControllerImpl implements OpenFlowController { | ... | @@ -43,7 +43,7 @@ public class OpenFlowControllerImpl implements OpenFlowController { |
43 | protected OpenFlowSwitchAgent agent = new OpenFlowSwitchAgent(); | 43 | protected OpenFlowSwitchAgent agent = new OpenFlowSwitchAgent(); |
44 | protected Set<OpenFlowSwitchListener> ofEventListener = new HashSet<>(); | 44 | protected Set<OpenFlowSwitchListener> ofEventListener = new HashSet<>(); |
45 | 45 | ||
46 | - protected List<PacketListener> ofPacketListener = new ArrayList<>(); | 46 | + protected Map<Integer, PacketListener> ofPacketListener = new TreeMap<>(); |
47 | 47 | ||
48 | private final Controller ctrl = new Controller(); | 48 | private final Controller ctrl = new Controller(); |
49 | 49 | ||
... | @@ -101,7 +101,7 @@ public class OpenFlowControllerImpl implements OpenFlowController { | ... | @@ -101,7 +101,7 @@ public class OpenFlowControllerImpl implements OpenFlowController { |
101 | 101 | ||
102 | @Override | 102 | @Override |
103 | public void addPacketListener(int priority, PacketListener listener) { | 103 | public void addPacketListener(int priority, PacketListener listener) { |
104 | - ofPacketListener.add(priority, listener); | 104 | + ofPacketListener.put(priority, listener); |
105 | } | 105 | } |
106 | 106 | ||
107 | @Override | 107 | @Override |
... | @@ -123,7 +123,7 @@ public class OpenFlowControllerImpl implements OpenFlowController { | ... | @@ -123,7 +123,7 @@ public class OpenFlowControllerImpl implements OpenFlowController { |
123 | } | 123 | } |
124 | break; | 124 | break; |
125 | case PACKET_IN: | 125 | case PACKET_IN: |
126 | - for (PacketListener p : ofPacketListener) { | 126 | + for (PacketListener p : ofPacketListener.values()) { |
127 | p.handlePacket(DefaultOpenFlowPacketContext | 127 | p.handlePacket(DefaultOpenFlowPacketContext |
128 | .packetContextFromPacketIn(this.getSwitch(dpid), | 128 | .packetContextFromPacketIn(this.getSwitch(dpid), |
129 | (OFPacketIn) msg)); | 129 | (OFPacketIn) msg)); | ... | ... |
providers/of/packet/src/main/java/org/onlab/onos/provider/of/packet/impl/OpenFlowPacketProvider.java
... | @@ -2,17 +2,24 @@ package org.onlab.onos.provider.of.packet.impl; | ... | @@ -2,17 +2,24 @@ package org.onlab.onos.provider.of.packet.impl; |
2 | 2 | ||
3 | import static org.slf4j.LoggerFactory.getLogger; | 3 | import static org.slf4j.LoggerFactory.getLogger; |
4 | 4 | ||
5 | +import java.nio.ByteBuffer; | ||
6 | + | ||
5 | import org.apache.felix.scr.annotations.Activate; | 7 | import org.apache.felix.scr.annotations.Activate; |
6 | import org.apache.felix.scr.annotations.Component; | 8 | import org.apache.felix.scr.annotations.Component; |
7 | import org.apache.felix.scr.annotations.Deactivate; | 9 | import org.apache.felix.scr.annotations.Deactivate; |
8 | import org.apache.felix.scr.annotations.Reference; | 10 | import org.apache.felix.scr.annotations.Reference; |
9 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 11 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
12 | +import org.onlab.onos.net.ConnectPoint; | ||
13 | +import org.onlab.onos.net.DeviceId; | ||
14 | +import org.onlab.onos.net.PortNumber; | ||
15 | +import org.onlab.onos.net.packet.DefaultInboundPacket; | ||
10 | import org.onlab.onos.net.packet.OutboundPacket; | 16 | import org.onlab.onos.net.packet.OutboundPacket; |
11 | import org.onlab.onos.net.packet.PacketProvider; | 17 | import org.onlab.onos.net.packet.PacketProvider; |
12 | import org.onlab.onos.net.packet.PacketProviderRegistry; | 18 | import org.onlab.onos.net.packet.PacketProviderRegistry; |
13 | import org.onlab.onos.net.packet.PacketProviderService; | 19 | import org.onlab.onos.net.packet.PacketProviderService; |
14 | import org.onlab.onos.net.provider.AbstractProvider; | 20 | import org.onlab.onos.net.provider.AbstractProvider; |
15 | import org.onlab.onos.net.provider.ProviderId; | 21 | import org.onlab.onos.net.provider.ProviderId; |
22 | +import org.onlab.onos.of.controller.Dpid; | ||
16 | import org.onlab.onos.of.controller.OpenFlowController; | 23 | import org.onlab.onos.of.controller.OpenFlowController; |
17 | import org.onlab.onos.of.controller.OpenFlowPacketContext; | 24 | import org.onlab.onos.of.controller.OpenFlowPacketContext; |
18 | import org.onlab.onos.of.controller.PacketListener; | 25 | import org.onlab.onos.of.controller.PacketListener; |
... | @@ -35,12 +42,8 @@ public class OpenFlowPacketProvider extends AbstractProvider implements PacketPr | ... | @@ -35,12 +42,8 @@ public class OpenFlowPacketProvider extends AbstractProvider implements PacketPr |
35 | 42 | ||
36 | private PacketProviderService providerService; | 43 | private PacketProviderService providerService; |
37 | 44 | ||
38 | - private final boolean useBDDP = true; | ||
39 | - | ||
40 | private final InternalPacketProvider listener = new InternalPacketProvider(); | 45 | private final InternalPacketProvider listener = new InternalPacketProvider(); |
41 | 46 | ||
42 | - | ||
43 | - | ||
44 | /** | 47 | /** |
45 | * Creates an OpenFlow link provider. | 48 | * Creates an OpenFlow link provider. |
46 | */ | 49 | */ |
... | @@ -51,7 +54,7 @@ public class OpenFlowPacketProvider extends AbstractProvider implements PacketPr | ... | @@ -51,7 +54,7 @@ public class OpenFlowPacketProvider extends AbstractProvider implements PacketPr |
51 | @Activate | 54 | @Activate |
52 | public void activate() { | 55 | public void activate() { |
53 | providerService = providerRegistry.register(this); | 56 | providerService = providerRegistry.register(this); |
54 | - controller.addPacketListener(0, listener); | 57 | + controller.addPacketListener(1, listener); |
55 | log.info("Started"); | 58 | log.info("Started"); |
56 | } | 59 | } |
57 | 60 | ||
... | @@ -65,18 +68,29 @@ public class OpenFlowPacketProvider extends AbstractProvider implements PacketPr | ... | @@ -65,18 +68,29 @@ public class OpenFlowPacketProvider extends AbstractProvider implements PacketPr |
65 | 68 | ||
66 | @Override | 69 | @Override |
67 | public void emit(OutboundPacket packet) { | 70 | public void emit(OutboundPacket packet) { |
68 | - // TODO Auto-generated method stub | ||
69 | 71 | ||
70 | } | 72 | } |
71 | 73 | ||
72 | 74 | ||
75 | + /** | ||
76 | + * Internal Packet Provider implementation. | ||
77 | + * | ||
78 | + */ | ||
73 | private class InternalPacketProvider implements PacketListener { | 79 | private class InternalPacketProvider implements PacketListener { |
74 | 80 | ||
75 | 81 | ||
76 | @Override | 82 | @Override |
77 | public void handlePacket(OpenFlowPacketContext pktCtx) { | 83 | public void handlePacket(OpenFlowPacketContext pktCtx) { |
84 | + DeviceId id = DeviceId.deviceId(Dpid.uri(pktCtx.dpid().value())); | ||
78 | 85 | ||
86 | + DefaultInboundPacket inPkt = new DefaultInboundPacket( | ||
87 | + new ConnectPoint(id, PortNumber.portNumber(pktCtx.inPort())), | ||
88 | + pktCtx.parsed(), ByteBuffer.wrap(pktCtx.unparsed())); | ||
79 | 89 | ||
90 | + OpenFlowCorePacketContext corePktCtx = | ||
91 | + new OpenFlowCorePacketContext(0, inPkt, null, false, pktCtx, | ||
92 | + controller.getSwitch(pktCtx.dpid())); | ||
93 | + providerService.processPacket(corePktCtx); | ||
80 | } | 94 | } |
81 | 95 | ||
82 | } | 96 | } | ... | ... |
-
Please register or login to post a comment