alshabib

added enhanced reactive forwarding

......@@ -5,6 +5,7 @@ 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.host.HostService;
import org.onlab.onos.net.packet.PacketProcessor;
import org.onlab.onos.net.packet.PacketService;
import org.onlab.onos.net.topology.TopologyService;
......@@ -18,11 +19,14 @@ public class ReactiveForwarding {
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected PacketService packetService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected HostService hostService;
private ReactivePacketProcessor processor;
@Activate
public void activate() {
processor = new ReactivePacketProcessor(topologyService);
processor = new ReactivePacketProcessor(topologyService, hostService);
packetService.addProcessor(processor, PacketProcessor.ADVISOR_MAX + 1);
}
......
......@@ -2,36 +2,73 @@ package org.onlab.onos.fwd;
import static org.slf4j.LoggerFactory.getLogger;
import java.util.Set;
import org.onlab.onos.net.Host;
import org.onlab.onos.net.HostId;
import org.onlab.onos.net.Path;
import org.onlab.onos.net.PortNumber;
import org.onlab.onos.net.flow.Instructions;
import org.onlab.onos.net.host.HostService;
import org.onlab.onos.net.packet.InboundPacket;
import org.onlab.onos.net.packet.PacketContext;
import org.onlab.onos.net.packet.PacketProcessor;
import org.onlab.onos.net.topology.TopologyService;
import org.onlab.packet.VLANID;
import org.slf4j.Logger;
public class ReactivePacketProcessor implements PacketProcessor {
private final Logger log = getLogger(getClass());
private final TopologyService topologyService;
private final HostService hostService;
public ReactivePacketProcessor(TopologyService topologyService) {
public ReactivePacketProcessor(TopologyService topologyService, HostService hostService) {
this.topologyService = topologyService;
this.hostService = hostService;
}
@Override
public void process(PacketContext context) {
InboundPacket pkt = context.inPacket();
HostId id = HostId.hostId(pkt.parsed().getDestinationMAC(), VLANID.vlanId((short) -1));
Host dst = hostService.getHost(id);
if (dst == null) {
flood(context);
return;
}
Set<Path> p = null;
if (pkt.receivedFrom().deviceId().equals(dst.location().deviceId())) {
context.treatmentBuilder().add(Instructions.createOutput(dst.location().port()));
context.send();
return;
} else {
p = topologyService.getPaths(topologyService.currentTopology(),
context.inPacket().receivedFrom().deviceId(), dst.location().deviceId());
}
if (p.isEmpty()) {
flood(context);
} else {
Path p1 = p.iterator().next();
context.treatmentBuilder().add(Instructions.createOutput(p1.src().port()));
context.send();
}
}
private void flood(PacketContext context) {
boolean canBcast = topologyService.isBroadcastPoint(topologyService.currentTopology(),
context.inPacket().receivedFrom());
if (canBcast) {
context.treatmentBuilder().add(Instructions.createOutput(PortNumber.FLOOD));
context.send();
} else {
context.block();
}
}
}
......
......@@ -84,6 +84,7 @@
com.sun.jersey.server.impl.container.servlet,
com.fasterxml.jackson.databind,
com.fasterxml.jackson.databind.node,
org.onlab.packet.*,
org.onlab.rest.*,
org.onlab.onos.*
</Import-Package>
......
package org.onlab.onos.provider.of.host.impl;
import static com.google.common.collect.Sets.newHashSet;
import static org.onlab.onos.net.DeviceId.deviceId;
import static org.onlab.onos.net.PortNumber.portNumber;
import static org.slf4j.LoggerFactory.getLogger;
import java.util.Set;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
......@@ -28,13 +35,6 @@ import org.onlab.packet.IPAddress;
import org.onlab.packet.VLANID;
import org.slf4j.Logger;
import java.util.Set;
import static com.google.common.collect.Sets.newHashSet;
import static org.onlab.onos.net.DeviceId.deviceId;
import static org.onlab.onos.net.PortNumber.portNumber;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Provider which uses an OpenFlow controller to detect network
* end-station hosts.
......@@ -96,7 +96,7 @@ public class OpenFlowHostProvider extends AbstractProvider implements HostProvid
if (eth.getEtherType() == Ethernet.TYPE_ARP) {
VLANID vlan = VLANID.vlanId(eth.getVlanID());
ConnectPoint heardOn = new ConnectPoint(deviceId(Dpid.uri(pktCtx.dpid())),
portNumber(pktCtx.inPort()));
portNumber(pktCtx.inPort()));
// If this is not an edge port, bail out.
Topology topology = topologyService.currentTopology();
......@@ -105,8 +105,8 @@ public class OpenFlowHostProvider extends AbstractProvider implements HostProvid
}
HostLocation hloc = new HostLocation(deviceId(Dpid.uri(pktCtx.dpid())),
portNumber(pktCtx.inPort()),
System.currentTimeMillis());
portNumber(pktCtx.inPort()),
System.currentTimeMillis());
HostId hid = HostId.hostId(eth.getSourceMAC(), vlan);
ARP arp = (ARP) eth.getPayload();
......
......@@ -54,7 +54,7 @@ public class OpenFlowPacketProvider extends AbstractProvider implements PacketPr
@Activate
public void activate() {
providerService = providerRegistry.register(this);
controller.addPacketListener(1, listener);
controller.addPacketListener(20, listener);
log.info("Started");
}
......