tom

Fixed traffic selector builder to allow only one criterion.

Temporarily disabled flow rule time-out.
......@@ -184,13 +184,13 @@ public class ReactiveForwarding {
// Install the flow rule to handle this type of message from now on.
Ethernet inPkt = context.inPacket().parsed();
TrafficSelector.Builder builder = new DefaultTrafficSelector.Builder();
TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
builder.matchEthType(inPkt.getEtherType())
.matchEthSrc(inPkt.getSourceMAC())
.matchEthDst(inPkt.getDestinationMAC())
.matchInport(context.inPacket().receivedFrom().port());
TrafficTreatment.Builder treat = new DefaultTrafficTreatment.Builder();
TrafficTreatment.Builder treat = DefaultTrafficTreatment.builder();
treat.setOutput(portNumber);
FlowRule f = new DefaultFlowRule(context.inPacket().receivedFrom().deviceId(),
......
......@@ -39,19 +39,15 @@ public class IntentInstallCommand extends AbstractShellCommand {
HostId srcId = HostId.hostId(src);
HostId dstId = HostId.hostId(dst);
TrafficSelector.Builder builder = new DefaultTrafficSelector.Builder();
builder
.matchEthSrc(hosts.getHost(srcId).mac())
TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
builder.matchEthSrc(hosts.getHost(srcId).mac())
.matchEthDst(hosts.getHost(dstId).mac());
TrafficTreatment.Builder treat = new DefaultTrafficTreatment.Builder();
TrafficTreatment.Builder treat = DefaultTrafficTreatment.builder();
HostToHostIntent intent = new HostToHostIntent(
new IntentId(id++),
srcId,
dstId,
builder.build(),
treat.build());
HostToHostIntent intent =
new HostToHostIntent(new IntentId(id++), srcId, dstId,
builder.build(), treat.build());
log.info("Adding intent {}", intent);
......
package org.onlab.onos.net.flow;
import static org.slf4j.LoggerFactory.getLogger;
import java.util.Collections;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import com.google.common.collect.ImmutableSet;
import org.onlab.onos.net.PortNumber;
import org.onlab.onos.net.flow.criteria.Criteria;
import org.onlab.onos.net.flow.criteria.Criterion;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
import org.slf4j.Logger;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
/**
* Default traffic selector implementation.
*/
public final class DefaultTrafficSelector implements TrafficSelector {
private final Set<Criterion> selector;
private final Set<Criterion> criteria;
private DefaultTrafficSelector(Set<Criterion> selector) {
this.selector = Collections.unmodifiableSet(selector);
/**
* Creates a new traffic selector with the specified criteria.
*
* @param criteria criteria
*/
private DefaultTrafficSelector(Set<Criterion> criteria) {
this.criteria = Collections.unmodifiableSet(criteria);
}
@Override
public Set<Criterion> criteria() {
return selector;
return criteria;
}
@Override
public int hashCode() {
return Objects.hash(selector);
return Objects.hash(criteria);
}
@Override
......@@ -40,23 +47,50 @@ public final class DefaultTrafficSelector implements TrafficSelector {
}
if (obj instanceof DefaultTrafficSelector) {
DefaultTrafficSelector that = (DefaultTrafficSelector) obj;
return Objects.equals(selector, that.selector);
return Objects.equals(criteria, that.criteria);
}
return false;
}
/**
* Returns a new traffic selector builder.
*
* @return traffic selector builder
*/
public static TrafficSelector.Builder builder() {
return new Builder();
}
/**
* Returns a new traffic selector builder primed to produce entities
* patterned after the supplied selector.
*
* @return traffic selector builder
*/
public static TrafficSelector.Builder builder(TrafficSelector selector) {
return new Builder(selector);
}
public static class Builder implements TrafficSelector.Builder {
/**
* Builder of traffic selector entities.
*/
public static final class Builder implements TrafficSelector.Builder {
private final Logger log = getLogger(getClass());
private final Map<Criterion.Type, Criterion> selector = new HashMap<>();
private final Set<Criterion> selector = new HashSet<>();
private Builder() {
}
private Builder(TrafficSelector selector) {
for (Criterion c : selector.criteria()) {
add(c);
}
}
@Override
public Builder add(Criterion criterion) {
selector.add(criterion);
selector.put(criterion.type(), criterion);
return this;
}
......@@ -107,7 +141,7 @@ public final class DefaultTrafficSelector implements TrafficSelector {
@Override
public TrafficSelector build() {
return new DefaultTrafficSelector(selector);
return new DefaultTrafficSelector(ImmutableSet.copyOf(selector.values()));
}
}
......
package org.onlab.onos.net.flow;
import static org.slf4j.LoggerFactory.getLogger;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import org.onlab.onos.net.PortNumber;
import org.onlab.onos.net.flow.instructions.Instruction;
import org.onlab.onos.net.flow.instructions.Instructions;
......@@ -14,10 +8,24 @@ import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
import org.slf4j.Logger;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Default traffic treatment implementation.
*/
public final class DefaultTrafficTreatment implements TrafficTreatment {
private final List<Instruction> instructions;
/**
* Creates a new traffic treatment from the specified list of instructions.
*
* @param instructions treatment instructions
*/
private DefaultTrafficTreatment(List<Instruction> instructions) {
this.instructions = Collections.unmodifiableList(instructions);
}
......@@ -28,12 +36,19 @@ public final class DefaultTrafficTreatment implements TrafficTreatment {
}
/**
* Builds a list of treatments following the following order.
* Modifications -> Group -> Output (including drop)
* Returns a new traffic treatment builder.
*
* @return traffic treatment builder
*/
public static TrafficTreatment.Builder builder() {
return new Builder();
}
public static class Builder implements TrafficTreatment.Builder {
/**
* Builds a list of treatments following the following order.
* Modifications -> Group -> Output (including drop)
*/
public static final class Builder implements TrafficTreatment.Builder {
private final Logger log = getLogger(getClass());
......@@ -47,6 +62,10 @@ public final class DefaultTrafficTreatment implements TrafficTreatment {
// TODO: should be a list of instructions based on modification objects
List<Instruction> modifications = new LinkedList<>();
// Creates a new builder
private Builder() {
}
public Builder add(Instruction instruction) {
if (drop) {
return this;
......
......@@ -24,7 +24,7 @@ public abstract class DefaultPacketContext implements PacketContext {
this.inPkt = inPkt;
this.outPkt = outPkt;
this.block = new AtomicBoolean(block);
this.builder = new DefaultTrafficTreatment.Builder();
this.builder = DefaultTrafficTreatment.builder();
}
@Override
......
......@@ -16,8 +16,8 @@ import org.onlab.onos.net.flow.TrafficTreatment;
public abstract class ConnectivityIntentTest extends IntentTest {
public static final IntentId IID = new IntentId(123);
public static final TrafficSelector MATCH = (new DefaultTrafficSelector.Builder()).build();
public static final TrafficTreatment NOP = (new DefaultTrafficTreatment.Builder()).build();
public static final TrafficSelector MATCH = DefaultTrafficSelector.builder().build();
public static final TrafficTreatment NOP = DefaultTrafficTreatment.builder().build();
public static final ConnectPoint P1 = new ConnectPoint(DeviceId.deviceId("111"), PortNumber.portNumber(0x1));
public static final ConnectPoint P2 = new ConnectPoint(DeviceId.deviceId("222"), PortNumber.portNumber(0x2));
......
......@@ -242,15 +242,16 @@ implements FlowRuleService, FlowRuleProviderRegistry {
}
private boolean checkRuleLiveness(FlowRule swRule, FlowRule storedRule) {
int timeout = storedRule.timeout();
if (storedRule.packets() != swRule.packets()) {
deadRounds.get(swRule).set(0);
return true;
}
return (deadRounds.get(swRule).getAndIncrement() *
FlowRuleProvider.POLL_INTERVAL) <= timeout;
// int timeout = storedRule.timeout();
// if (storedRule.packets() != swRule.packets()) {
// deadRounds.get(swRule).set(0);
// return true;
// }
//
// return (deadRounds.get(swRule).getAndIncrement() *
// FlowRuleProvider.POLL_INTERVAL) <= timeout;
//
}
// Posts the specified event to the local event dispatcher.
......
......@@ -150,7 +150,7 @@ public class HostMonitor implements TimerTask {
List<Instruction> instructions = new ArrayList<>();
instructions.add(Instructions.createOutput(port.number()));
TrafficTreatment treatment = new DefaultTrafficTreatment.Builder()
TrafficTreatment treatment = DefaultTrafficTreatment.builder()
.setOutput(port.number())
.build();
......
package org.onlab.onos.net.intent.impl;
import java.util.Iterator;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
......@@ -17,24 +15,25 @@ import org.onlab.onos.net.flow.FlowRule;
import org.onlab.onos.net.flow.FlowRuleService;
import org.onlab.onos.net.flow.TrafficSelector;
import org.onlab.onos.net.flow.TrafficTreatment;
import org.onlab.onos.net.flow.criteria.Criterion;
import org.onlab.onos.net.intent.IntentExtensionService;
import org.onlab.onos.net.intent.IntentInstaller;
import org.onlab.onos.net.intent.PathIntent;
import java.util.Iterator;
/**
* An intent installer for {@link PathIntent}.
* Installer for {@link PathIntent path connectivity intents}.
*/
@Component(immediate = true)
public class PathIntentInstaller
implements IntentInstaller<PathIntent> {
public class PathIntentInstaller implements IntentInstaller<PathIntent> {
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected IntentExtensionService intentManager;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
private FlowRuleService flowRuleService;
protected FlowRuleService flowRuleService;
private final ApplicationId appId = ApplicationId.valueOf(1);
private final ApplicationId appId = ApplicationId.getAppId();
@Activate
public void activate() {
......@@ -48,24 +47,21 @@ public class PathIntentInstaller
@Override
public void install(PathIntent intent) {
TrafficSelector.Builder builder = new DefaultTrafficSelector.Builder();
TrafficSelector selector = intent.getTrafficSelector();
for (Criterion c : selector.criteria()) {
builder.add(c);
}
TrafficSelector.Builder builder =
DefaultTrafficSelector.builder(intent.getTrafficSelector());
Iterator<Link> links = intent.getPath().links().iterator();
ConnectPoint prev = links.next().dst();
while (links.hasNext()) {
builder.matchInport(prev.port());
Link link = links.next();
TrafficTreatment.Builder treat = new DefaultTrafficTreatment.Builder();
TrafficTreatment.Builder treat = DefaultTrafficTreatment.builder();
treat.setOutput(link.src().port());
FlowRule f = new DefaultFlowRule(link.src().deviceId(),
builder.build(), treat.build(), 0, appId, 0);
flowRuleService.applyFlowRules(f);
FlowRule rule = new DefaultFlowRule(link.src().deviceId(),
builder.build(), treat.build(),
0, appId, 30);
flowRuleService.applyFlowRules(rule);
prev = link.dst();
}
......
......@@ -43,7 +43,6 @@ import com.google.common.collect.HashMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
@Component(immediate = true)
@Service
public class ProxyArpManager implements ProxyArpService {
......@@ -128,7 +127,7 @@ public class ProxyArpManager implements ProxyArpService {
Ethernet arpReply = buildArpReply(dst, eth);
// TODO: check send status with host service.
TrafficTreatment.Builder builder = new DefaultTrafficTreatment.Builder();
TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
builder.setOutput(src.location().port());
packetService.emit(new DefaultOutboundPacket(src.location().deviceId(),
builder.build(), ByteBuffer.wrap(arpReply.serialize())));
......@@ -148,7 +147,7 @@ public class ProxyArpManager implements ProxyArpService {
if (h == null) {
flood(eth);
} else {
TrafficTreatment.Builder builder = new DefaultTrafficTreatment.Builder();
TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
builder.setOutput(h.location().port());
packetService.emit(new DefaultOutboundPacket(h.location().deviceId(),
builder.build(), ByteBuffer.wrap(eth.serialize())));
......@@ -166,7 +165,7 @@ public class ProxyArpManager implements ProxyArpService {
synchronized (externalPorts) {
for (Entry<Device, PortNumber> entry : externalPorts.entries()) {
builder = new DefaultTrafficTreatment.Builder();
builder = DefaultTrafficTreatment.builder();
builder.setOutput(entry.getValue());
packetService.emit(new DefaultOutboundPacket(entry.getKey().id(),
builder.build(), buf));
......
......@@ -86,7 +86,7 @@ public class FlowRuleBuilder {
private TrafficTreatment buildTreatment() {
TrafficTreatment.Builder builder = new DefaultTrafficTreatment.Builder();
TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
// If this is a drop rule
if (actions.size() == 0) {
builder.drop();
......@@ -171,7 +171,7 @@ public class FlowRuleBuilder {
}
private TrafficSelector buildSelector() {
TrafficSelector.Builder builder = new DefaultTrafficSelector.Builder();
TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
for (MatchField<?> field : match.getMatchFields()) {
switch (field.id) {
case IN_PORT:
......
......@@ -181,7 +181,7 @@ public class OpenFlowPacketProviderTest {
}
private static TrafficTreatment treatment(Instruction ... insts) {
TrafficTreatment.Builder builder = new DefaultTrafficTreatment.Builder();
TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
for (Instruction i : insts) {
builder.add(i);
}
......
......@@ -21,7 +21,7 @@ export PATH="$PATH:."
# e.g. 'o api', 'o dev', 'o'
function o {
cd $(find $ONOS_ROOT/ -type d | egrep -v '\.git|target' | \
egrep "${1:-$ONOS_ROOT}" | head -n 1)
egrep "${1:-$ONOS_ROOT}" | egrep -v "$ONOS_ROOT/.+/src/" | head -n 1)
}
# Short-hand for 'mvn clean install' for us lazy folk
......