alshabib

sample app launched

package org.onlab.onos.fwd;
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.packet.PacketProcessor;
import org.onlab.onos.net.packet.PacketService;
import org.onlab.onos.net.topology.TopologyService;
@Component
public class ReactiveForwarding {
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected TopologyService topologyService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected PacketService packetService;
private ReactivePacketProcessor processor;
@Activate
public void activate() {
processor = new ReactivePacketProcessor(topologyService);
packetService.addProcessor(processor, PacketProcessor.ADVISOR_MAX + 1);
}
@Deactivate
public void deactivate() {
packetService.removeProcessor(processor);
processor = null;
}
}
package org.onlab.onos.net.trivial.packet.impl;
package org.onlab.onos.fwd;
import static org.slf4j.LoggerFactory.getLogger;
......@@ -6,16 +6,32 @@ import org.onlab.onos.net.PortNumber;
import org.onlab.onos.net.flow.Instructions;
import org.onlab.onos.net.packet.PacketContext;
import org.onlab.onos.net.packet.PacketProcessor;
import org.onlab.onos.net.topology.TopologyService;
import org.slf4j.Logger;
public class ReactivePacketProcessor implements PacketProcessor {
private final Logger log = getLogger(getClass());
private final TopologyService topologyService;
public ReactivePacketProcessor(TopologyService topologyService) {
this.topologyService = topologyService;
}
@Override
public void process(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();
}
}
}
......
......@@ -18,6 +18,7 @@
<modules>
<module>tvue</module>
<module>fwd</module>
</modules>
<properties>
......
......@@ -6,7 +6,6 @@ import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import org.onlab.onos.net.PortNumber;
import org.slf4j.Logger;
@SuppressWarnings("rawtypes")
......@@ -33,29 +32,33 @@ public class DefaultTrafficTreatment implements TrafficTreatment {
private final Logger log = getLogger(getClass());
List<Instruction<PortNumber>> outputs = new LinkedList<>();
boolean drop = false;
List<Instruction> outputs = new LinkedList<>();
// TODO: should be a list of instructions based on group objects
List<Instruction<Object>> groups = new LinkedList<>();
List<Instruction> groups = new LinkedList<>();
// TODO: should be a list of instructions based on modification objects
List<Instruction<Object>> modifications = new LinkedList<>();
List<Instruction> modifications = new LinkedList<>();
@SuppressWarnings("unchecked")
@Override
public Builder add(Instruction instruction) {
switch (instruction.type()) {
case OUTPUT:
case DROP:
// TODO: should check that there is only one drop instruction.
drop = true;
break;
case OUTPUT:
outputs.add(instruction);
break;
case MODIFICATION:
// TODO: enforce modification order if any
modifications.add(instruction);
break;
case GROUP:
groups.add(instruction);
break;
default:
log.warn("Unknown instruction type {}", instruction.type());
}
......@@ -64,10 +67,14 @@ public class DefaultTrafficTreatment implements TrafficTreatment {
@Override
public TrafficTreatment build() {
//If we are dropping should we just return an emptry list?
List<Instruction> instructions = new LinkedList<Instruction>();
instructions.addAll(modifications);
instructions.addAll(groups);
if (!drop) {
instructions.addAll(outputs);
}
return new DefaultTrafficTreatment(instructions);
}
......
......@@ -4,7 +4,7 @@ package org.onlab.onos.net.flow;
* Abstraction of a single traffic treatment step.
* @param <T> the type parameter for the instruction
*/
public interface Instruction<T> {
public interface Instruction {
/**
* Represents the type of traffic treatment.
......@@ -41,10 +41,4 @@ public interface Instruction<T> {
*/
public Type type();
/**
* Returns the actual value of the instruction.
* @return the value for this instruction
*/
public T instruction();
}
......
package org.onlab.onos.net.flow;
import org.onlab.onos.net.PortNumber;
import static com.google.common.base.Preconditions.checkNotNull;
import org.onlab.onos.net.PortNumber;
/**
* Factory class for creating various traffic treatment instructions.
*/
......@@ -17,22 +18,44 @@ public final class Instructions {
* @param number port number
* @return output instruction
*/
public static Instruction<PortNumber> createOutput(final PortNumber number) {
return new Instruction<PortNumber>() {
public static OutputInstruction createOutput(final PortNumber number) {
checkNotNull(number, "PortNumber cannot be null");
return new OutputInstruction(number);
}
@Override
public Instruction.Type type() {
return Type.OUTPUT;
public static DropInstruction createDrop() {
return new DropInstruction();
}
// TODO: add create methods
public static final class DropInstruction implements Instruction {
@Override
public PortNumber instruction() {
return number;
public Type type() {
return Type.DROP;
}
}
};
public static final class OutputInstruction implements Instruction {
private final PortNumber port;
private OutputInstruction(PortNumber port) {
this.port = port;
}
// TODO: add create methods
public PortNumber port() {
return port;
}
@Override
public Type type() {
return Type.OUTPUT;
}
}
}
......
......@@ -51,7 +51,7 @@ public abstract class DefaultPacketContext implements PacketContext {
public abstract void send();
@Override
public boolean blocked() {
public boolean block() {
return this.block.getAndSet(true);
}
......
......@@ -45,7 +45,7 @@ public interface PacketContext {
* Blocks the outbound packet from being sent from this point onward.
* @return whether the outbound packet is blocked.
*/
boolean blocked();
boolean block();
/**
* Check whether the outbound packet is blocked.
......
package org.onlab.onos.event;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.onlab.junit.TestTools.delay;
import static org.onlab.onos.event.TestEvent.Type.FOO;
import java.util.List;
import java.util.Timer;
import static org.junit.Assert.*;
import static org.onlab.junit.TestTools.delay;
import static org.onlab.onos.event.TestEvent.Type.FOO;
import org.junit.Test;
/**
* Tests the operation of the accumulator.
......
package org.onlab.onos.net.trivial.packet.impl;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.slf4j.LoggerFactory.getLogger;
import java.util.Map;
......@@ -42,22 +43,20 @@ implements PacketService, PacketProviderRegistry {
private final Map<Integer, PacketProcessor> processors = new TreeMap<>();
private final PacketProcessor reactiveProcessor = new ReactivePacketProcessor();
@Activate
public void activate() {
addProcessor(reactiveProcessor, PacketProcessor.ADVISOR_MAX + 1);
log.info("Started");
}
@Deactivate
public void deactivate() {
removeProcessor(reactiveProcessor);
log.info("Stopped");
}
@Override
public void addProcessor(PacketProcessor processor, int priority) {
checkNotNull(processor, "Processor cannot be null");
processors.put(priority, processor);
}
......
......@@ -79,4 +79,11 @@
<bundle>mvn:org.onlab.onos/onos-app-tvue/1.0.0-SNAPSHOT</bundle>
</feature>
<feature name="onos-app-fwd" version="1.0.0"
description="ONOS sample forwarding application">
<feature>onos-core</feature>
<bundle>mvn:org.onlab.onos/onos-app-fwd/1.0.0-SNAPSHOT</bundle>
</feature>
</features>
......
......@@ -7,6 +7,7 @@ import java.util.List;
import org.onlab.onos.net.PortNumber;
import org.onlab.onos.net.flow.Instruction;
import org.onlab.onos.net.flow.Instruction.Type;
import org.onlab.onos.net.flow.Instructions.OutputInstruction;
import org.onlab.onos.net.packet.DefaultPacketContext;
import org.onlab.onos.net.packet.InboundPacket;
import org.onlab.onos.net.packet.OutboundPacket;
......@@ -29,7 +30,7 @@ public class OpenFlowCorePacketContext extends DefaultPacketContext {
@Override
public void send() {
if (!this.blocked()) {
if (!this.block()) {
if (outPacket() == null) {
sendBufferedPacket();
} else {
......@@ -42,14 +43,13 @@ public class OpenFlowCorePacketContext extends DefaultPacketContext {
}
}
@SuppressWarnings({ "rawtypes", "unchecked" })
private void sendBufferedPacket() {
List<Instruction> ins = treatmentBuilder().build().instructions();
OFPort p = null;
//TODO: support arbitrary list of treatments
for (Instruction i : ins) {
if (i.type() == Type.OUTPUT) {
p = buildPort(((Instruction<PortNumber>) i).instruction());
p = buildPort(((OutputInstruction) i).port());
break; //for now...
}
}
......