alshabib

receiving packet ins

......@@ -2,7 +2,8 @@ package org.onlab.onos.net.trivial.packet.impl;
import static org.slf4j.LoggerFactory.getLogger;
import java.util.ArrayList;
import java.util.Map;
import java.util.TreeMap;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
......@@ -39,7 +40,7 @@ implements PacketService, PacketProviderRegistry {
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
private DeviceService deviceService;
private final ArrayList<PacketProcessor> processors = new ArrayList<>();
private final Map<Integer, PacketProcessor> processors = new TreeMap<>();
private final PacketProcessor reactiveProcessor = new ReactivePacketProcessor();
......@@ -57,12 +58,12 @@ implements PacketService, PacketProviderRegistry {
@Override
public void addProcessor(PacketProcessor processor, int priority) {
processors.add(priority, processor);
processors.put(priority, processor);
}
@Override
public void removeProcessor(PacketProcessor processor) {
processors.remove(processor);
processors.values().remove(processor);
}
@Override
......@@ -89,7 +90,7 @@ implements PacketService, PacketProviderRegistry {
@Override
public void processPacket(PacketContext context) {
for (PacketProcessor processor : processors) {
for (PacketProcessor processor : processors.values()) {
processor.process(context);
}
}
......
......@@ -68,6 +68,8 @@
<bundle>mvn:org.onlab.onos/onos-of-provider-device/1.0.0-SNAPSHOT</bundle>
<bundle>mvn:org.onlab.onos/onos-of-provider-link/1.0.0-SNAPSHOT</bundle>
<bundle>mvn:org.onlab.onos/onos-of-provider-host/1.0.0-SNAPSHOT</bundle>
<bundle>mvn:org.onlab.onos/onos-of-provider-packet/1.0.0-SNAPSHOT</bundle>
</feature>
<feature name="onos-app-tvue" version="1.0.0"
......
......@@ -33,8 +33,8 @@ public final class DefaultOpenFlowPacketContext implements OpenFlowPacketContext
public void send() {
if (free && isBuilt) {
sw.sendMsg(pktout);
block();
}
}
@Override
......
package org.onlab.onos.of.controller.impl;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
......@@ -43,7 +43,7 @@ public class OpenFlowControllerImpl implements OpenFlowController {
protected OpenFlowSwitchAgent agent = new OpenFlowSwitchAgent();
protected Set<OpenFlowSwitchListener> ofEventListener = new HashSet<>();
protected List<PacketListener> ofPacketListener = new ArrayList<>();
protected Map<Integer, PacketListener> ofPacketListener = new TreeMap<>();
private final Controller ctrl = new Controller();
......@@ -101,7 +101,7 @@ public class OpenFlowControllerImpl implements OpenFlowController {
@Override
public void addPacketListener(int priority, PacketListener listener) {
ofPacketListener.add(priority, listener);
ofPacketListener.put(priority, listener);
}
@Override
......@@ -123,7 +123,7 @@ public class OpenFlowControllerImpl implements OpenFlowController {
}
break;
case PACKET_IN:
for (PacketListener p : ofPacketListener) {
for (PacketListener p : ofPacketListener.values()) {
p.handlePacket(DefaultOpenFlowPacketContext
.packetContextFromPacketIn(this.getSwitch(dpid),
(OFPacketIn) msg));
......
......@@ -2,17 +2,24 @@ package org.onlab.onos.provider.of.packet.impl;
import static org.slf4j.LoggerFactory.getLogger;
import java.nio.ByteBuffer;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.PortNumber;
import org.onlab.onos.net.packet.DefaultInboundPacket;
import org.onlab.onos.net.packet.OutboundPacket;
import org.onlab.onos.net.packet.PacketProvider;
import org.onlab.onos.net.packet.PacketProviderRegistry;
import org.onlab.onos.net.packet.PacketProviderService;
import org.onlab.onos.net.provider.AbstractProvider;
import org.onlab.onos.net.provider.ProviderId;
import org.onlab.onos.of.controller.Dpid;
import org.onlab.onos.of.controller.OpenFlowController;
import org.onlab.onos.of.controller.OpenFlowPacketContext;
import org.onlab.onos.of.controller.PacketListener;
......@@ -35,12 +42,8 @@ public class OpenFlowPacketProvider extends AbstractProvider implements PacketPr
private PacketProviderService providerService;
private final boolean useBDDP = true;
private final InternalPacketProvider listener = new InternalPacketProvider();
/**
* Creates an OpenFlow link provider.
*/
......@@ -51,7 +54,7 @@ public class OpenFlowPacketProvider extends AbstractProvider implements PacketPr
@Activate
public void activate() {
providerService = providerRegistry.register(this);
controller.addPacketListener(0, listener);
controller.addPacketListener(1, listener);
log.info("Started");
}
......@@ -65,18 +68,29 @@ public class OpenFlowPacketProvider extends AbstractProvider implements PacketPr
@Override
public void emit(OutboundPacket packet) {
// TODO Auto-generated method stub
}
/**
* Internal Packet Provider implementation.
*
*/
private class InternalPacketProvider implements PacketListener {
@Override
public void handlePacket(OpenFlowPacketContext pktCtx) {
DeviceId id = DeviceId.deviceId(Dpid.uri(pktCtx.dpid().value()));
DefaultInboundPacket inPkt = new DefaultInboundPacket(
new ConnectPoint(id, PortNumber.portNumber(pktCtx.inPort())),
pktCtx.parsed(), ByteBuffer.wrap(pktCtx.unparsed()));
OpenFlowCorePacketContext corePktCtx =
new OpenFlowCorePacketContext(0, inPkt, null, false, pktCtx,
controller.getSwitch(pktCtx.dpid()));
providerService.processPacket(corePktCtx);
}
}
......