alshabib

building flowrules

Showing 40 changed files with 458 additions and 244 deletions
......@@ -169,7 +169,7 @@ public class ReactiveForwarding {
treat.add(Instructions.createOutput(portNumber));
FlowRule f = new DefaultFlowRule(context.inPacket().receivedFrom().deviceId(),
builder.build(), treat.build());
builder.build(), treat.build(), 0);
flowRuleService.applyFlowRules(f);
}
......
package org.onlab.onos.net.flow;
import static com.google.common.base.MoreObjects.toStringHelper;
import org.onlab.onos.net.DeviceId;
public class DefaultFlowEntry extends DefaultFlowRule implements FlowEntry {
private final int priority;
private final long created;
private final FlowId id;
public DefaultFlowEntry(DefaultFlowEntry entry) {
super(entry.deviceId(), entry.selector(), entry.treatment());
this.priority = entry.priority;
this.created = entry.created;
this.id = entry.id;
}
public DefaultFlowEntry(DeviceId deviceId, TrafficSelector selector,
TrafficTreatment treatment, int priority) {
super(deviceId, selector, treatment);
this.priority = priority;
this.created = System.currentTimeMillis();
this.id = FlowId.valueOf(this.hashCode());
}
@Override
public FlowId id() {
return null;
}
@Override
public int priority() {
return priority;
}
@Override
public long lifeMillis() {
return (created - System.currentTimeMillis());
}
@Override
public long idleMillis() {
return 0;
}
@Override
public long packets() {
return 0;
}
@Override
public long bytes() {
return 0;
}
@Override
/*
* currently uses the parts that definitely have a defined hashcode...
*
* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
final int prime = 31;
int result = prime * this.deviceId().hashCode();
result = prime * result + this.priority;
result = prime * result + this.selector().hashCode();
result = prime * result + this.treatment().hashCode();
return result;
}
@Override
/*
* The priority and statistics can change on a given treatment and selector
*
* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object obj) {
if (obj instanceof DefaultFlowEntry) {
DefaultFlowEntry that = (DefaultFlowEntry) obj;
if (!this.deviceId().equals(that.deviceId())) {
return false;
}
if (!(this.priority == that.priority)) {
return false;
}
return super.equals(obj);
}
return false;
}
@Override
public String toString() {
return toStringHelper(this)
.add("id", id)
.add("deviceId", deviceId())
.add("priority", priority)
.add("selector", selector())
.add("treatment", treatment())
.toString();
}
}
package org.onlab.onos.net.flow;
import static com.google.common.base.MoreObjects.toStringHelper;
import org.onlab.onos.net.DeviceId;
public class DefaultFlowRule implements FlowRule {
private final DeviceId deviceId;
private final int priority;
private final TrafficSelector selector;
private final TrafficTreatment treatment;
private final DeviceId deviceId;
private final FlowId id;
private final long created;
private long life;
private long idle;
private long packets;
private long bytes;
public DefaultFlowRule(DeviceId deviceId,
TrafficSelector selector, TrafficTreatment treatment) {
this.treatment = treatment;
this.selector = selector;
TrafficSelector selector, TrafficTreatment treatment, int priority) {
this.deviceId = deviceId;
this.priority = priority;
this.selector = selector;
this.treatment = treatment;
this.life = 0;
this.idle = 0;
this.packets = 0;
this.bytes = 0;
this.id = FlowId.valueOf(this.hashCode());
this.created = System.currentTimeMillis();
}
// TODO: Decide whether to take the flowId from the underlying flowentry.
public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector,
TrafficTreatment treatment, int priority,
long life, long idle, long packets, long bytes) {
this(deviceId, selector, treatment, priority);
this.life = life;
this.idle = idle;
this.packets = packets;
this.bytes = bytes;
}
@Override
public FlowId id() {
return id;
}
@Override
public int priority() {
// is this supposed to be 0?
return 0;
return priority;
}
@Override
......@@ -37,6 +70,32 @@ public class DefaultFlowRule implements FlowRule {
}
@Override
public long lifeMillis() {
return life;
}
@Override
public long idleMillis() {
return idle;
}
@Override
public long packets() {
return packets;
}
@Override
public long bytes() {
return bytes;
}
@Override
/*
* The priority and statistics can change on a given treatment and selector
*
* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
public int hashCode() {
final int prime = 31;
int result = prime * this.deviceId().hashCode();
......@@ -69,5 +128,16 @@ public class DefaultFlowRule implements FlowRule {
return false;
}
@Override
public String toString() {
return toStringHelper(this)
.add("id", id)
.add("deviceId", deviceId)
.add("priority", priority)
.add("selector", selector)
.add("treatment", treatment)
.add("created", created)
.toString();
}
}
......
package org.onlab.onos.net.flow;
/**
* Represents a flow rule and its associated accumulated metrics.
*/
public interface FlowEntry extends FlowRule {
/**
* Returns the ID of this flow.
*
* @return the flow ID
*/
FlowId id();
/**
* Returns the number of milliseconds this flow rule has been applied.
*
* @return number of millis
*/
long lifeMillis();
/**
* Returns the number of milliseconds this flow rule has been idle.
*
* @return number of millis
*/
long idleMillis();
/**
* Returns the number of packets this flow rule has matched.
*
* @return number of packets
*/
long packets();
/**
* Returns the number of bytes this flow rule has matched.
*
* @return number of bytes
*/
long bytes();
}
......@@ -9,6 +9,12 @@ import org.onlab.onos.net.DeviceId;
public interface FlowRule {
//TODO: build cookie value
/**
* Returns the ID of this flow.
*
* @return the flow ID
*/
FlowId id();
/**
* Returns the flow rule priority given in natural order; higher numbers
......@@ -40,4 +46,32 @@ public interface FlowRule {
*/
TrafficTreatment treatment();
/**
* Returns the number of milliseconds this flow rule has been applied.
*
* @return number of millis
*/
long lifeMillis();
/**
* Returns the number of milliseconds this flow rule has been idle.
*
* @return number of millis
*/
long idleMillis();
/**
* Returns the number of packets this flow rule has matched.
*
* @return number of packets
*/
long packets();
/**
* Returns the number of bytes this flow rule has matched.
*
* @return number of bytes
*/
long bytes();
}
......
......@@ -25,5 +25,4 @@ public interface FlowRuleProvider extends Provider {
*/
void removeFlowRule(FlowRule... flowRules);
}
......
......@@ -21,7 +21,7 @@ public interface FlowRuleService {
* @param deviceId device identifier
* @return collection of flow rules
*/
Iterable<FlowEntry> getFlowEntries(DeviceId deviceId);
Iterable<FlowRule> getFlowEntries(DeviceId deviceId);
// TODO: add createFlowRule factory method and execute operations method
......@@ -34,7 +34,7 @@ public interface FlowRuleService {
* throws SomeKindOfException that indicates which ones were applied and
* which ones failed
*/
List<FlowEntry> applyFlowRules(FlowRule... flowRules);
List<FlowRule> applyFlowRules(FlowRule... flowRules);
/**
* Removes the specified flow rules from their respective devices. If the
......
package org.onlab.onos.net.provider;
import com.google.common.collect.ImmutableSet;
import org.onlab.onos.net.DeviceId;
import java.util.HashMap;
import java.util.Map;
......@@ -20,6 +21,7 @@ public abstract class AbstractProviderRegistry<P extends Provider, S extends Pro
private final Map<ProviderId, P> providers = new HashMap<>();
private final Map<ProviderId, S> services = new HashMap<>();
private final Map<String, P> providersByScheme = new HashMap<>();
/**
* Creates a new provider service bound to the specified provider.
......@@ -65,4 +67,14 @@ public abstract class AbstractProviderRegistry<P extends Provider, S extends Pro
return providers.get(providerId);
}
/**
* Returns the provider for the specified device ID based on URI scheme.
*
* @param deviceId device identifier
* @return provider bound to the URI scheme
*/
protected synchronized P getProvider(DeviceId deviceId) {
return providersByScheme.get(deviceId.uri().getScheme());
}
}
......
......@@ -9,6 +9,7 @@ import static com.google.common.base.MoreObjects.toStringHelper;
*/
public class ProviderId {
private final String scheme;
private final String id;
/**
......@@ -16,15 +17,26 @@ public class ProviderId {
* The providers are expected to follow the reverse DNS convention, e.g.
* {@code org.onlab.onos.provider.of.device}
*
* @param id string identifier
* @param scheme device URI scheme to which this provider is bound, e.g. "of", "snmp"
* @param id string identifier
*/
public ProviderId(String id) {
public ProviderId(String scheme, String id) {
this.scheme = scheme;
this.id = id;
}
/**
* Returns the device URI scheme to which this provider is bound.
*
* @return device URI scheme
*/
public String scheme() {
return scheme;
}
@Override
public int hashCode() {
return Objects.hash(id);
return Objects.hash(scheme, id);
}
@Override
......@@ -36,12 +48,13 @@ public class ProviderId {
return false;
}
final ProviderId other = (ProviderId) obj;
return Objects.equals(this.id, other.id);
return Objects.equals(this.scheme, other.scheme) &&
Objects.equals(this.id, other.id);
}
@Override
public String toString() {
return toStringHelper(this).add("id", id).toString();
return toStringHelper(this).add("scheme", scheme).add("id", id).toString();
}
}
......
......@@ -13,7 +13,7 @@ import static org.onlab.onos.net.DeviceId.deviceId;
*/
public class DefaultDeviceTest {
private static final ProviderId PID = new ProviderId("foo");
private static final ProviderId PID = new ProviderId("of", "foo");
private static final DeviceId DID1 = deviceId("of:foo");
private static final DeviceId DID2 = deviceId("of:bar");
private static final String MFR = "whitebox";
......
......@@ -15,7 +15,7 @@ import static org.onlab.onos.net.PortNumber.portNumber;
*/
public class DefaultEdgeLinkTest {
private static final ProviderId PID = new ProviderId("foo");
private static final ProviderId PID = new ProviderId("of", "foo");
private static final DeviceId DID1 = deviceId("of:foo");
private static final HostId HID1 = hostId("nic:foobar");
private static final HostId HID2 = hostId("nic:barfoo");
......
......@@ -15,7 +15,7 @@ import static org.onlab.onos.net.PortNumber.portNumber;
*/
public class DefaultLinkTest {
private static final ProviderId PID = new ProviderId("foo");
private static final ProviderId PID = new ProviderId("of", "foo");
private static final DeviceId DID1 = deviceId("of:foo");
private static final DeviceId DID2 = deviceId("of:bar");
private static final PortNumber P1 = portNumber(1);
......
......@@ -14,7 +14,7 @@ import static org.onlab.onos.net.PortNumber.portNumber;
*/
public class DefaultPortTest {
private static final ProviderId PID = new ProviderId("foo");
private static final ProviderId PID = new ProviderId("of", "foo");
private static final DeviceId DID1 = deviceId("of:foo");
private static final DeviceId DID2 = deviceId("of:bar");
private static final PortNumber P1 = portNumber(1);
......
......@@ -17,7 +17,7 @@ import com.google.common.collect.Sets;
*/
public abstract class TestDeviceParams {
protected static final ProviderId PID = new ProviderId("foo");
protected static final ProviderId PID = new ProviderId("of", "foo");
protected static final DeviceId DID1 = deviceId("of:foo");
protected static final DeviceId DID2 = deviceId("of:bar");
protected static final MacAddress MAC1 = MacAddress.valueOf("00:11:00:00:00:01");
......
......@@ -18,7 +18,7 @@ import org.onlab.onos.net.provider.ProviderId;
public class DeviceEventTest extends AbstractEventTest {
private Device createDevice() {
return new DefaultDevice(new ProviderId("foo"), deviceId("of:foo"),
return new DefaultDevice(new ProviderId("of", "foo"), deviceId("of:foo"),
Device.Type.SWITCH, "box", "hw", "sw", "sn");
}
......
......@@ -34,7 +34,7 @@ public class HostEventTest extends AbstractEventTest {
HostId hid = HostId.hostId(mac, vlan);
return new DefaultHost(
new ProviderId("foo"), hid, mac, vlan, loc, ipset);
new ProviderId("of", "foo"), hid, mac, vlan, loc, ipset);
}
@Override
......
......@@ -16,7 +16,7 @@ import static org.onlab.onos.net.PortNumber.portNumber;
public class LinkEventTest extends AbstractEventTest {
private Link createLink() {
return new DefaultLink(new ProviderId("foo"),
return new DefaultLink(new ProviderId("of", "foo"),
new ConnectPoint(deviceId("of:foo"), portNumber(1)),
new ConnectPoint(deviceId("of:bar"), portNumber(2)),
Link.Type.INDIRECT);
......
......@@ -28,14 +28,14 @@ public class AbstractProviderRegistryTest {
TestProviderRegistry registry = new TestProviderRegistry();
assertEquals("incorrect provider count", 0, registry.getProviders().size());
ProviderId fooId = new ProviderId("foo");
ProviderId fooId = new ProviderId("of", "foo");
TestProvider pFoo = new TestProvider(fooId);
TestProviderService psFoo = registry.register(pFoo);
assertEquals("incorrect provider count", 1, registry.getProviders().size());
assertThat("provider not found", registry.getProviders().contains(fooId));
assertEquals("incorrect provider", psFoo.provider(), pFoo);
ProviderId barId = new ProviderId("bar");
ProviderId barId = new ProviderId("of", "bar");
TestProvider pBar = new TestProvider(barId);
TestProviderService psBar = registry.register(pBar);
assertEquals("incorrect provider count", 2, registry.getProviders().size());
......@@ -52,7 +52,7 @@ public class AbstractProviderRegistryTest {
@Test(expected = IllegalStateException.class)
public void duplicateRegistration() {
TestProviderRegistry registry = new TestProviderRegistry();
TestProvider pFoo = new TestProvider(new ProviderId("foo"));
TestProvider pFoo = new TestProvider(new ProviderId("of", "foo"));
registry.register(pFoo);
registry.register(pFoo);
}
......@@ -60,13 +60,13 @@ public class AbstractProviderRegistryTest {
@Test
public void voidUnregistration() {
TestProviderRegistry registry = new TestProviderRegistry();
registry.unregister(new TestProvider(new ProviderId("foo")));
registry.unregister(new TestProvider(new ProviderId("of", "foo")));
}
@Test(expected = IllegalStateException.class)
public void unregistration() {
TestProviderRegistry registry = new TestProviderRegistry();
TestProvider pFoo = new TestProvider(new ProviderId("foo"));
TestProvider pFoo = new TestProvider(new ProviderId("of", "foo"));
TestProviderService psFoo = registry.register(pFoo);
registry.unregister(pFoo);
psFoo.checkValidity();
......
......@@ -11,7 +11,7 @@ public class AbstractProviderTest {
@Test
public void basics() {
ProviderId id = new ProviderId("foo.bar");
ProviderId id = new ProviderId("of", "foo.bar");
TestProvider provider = new TestProvider(id);
assertEquals("incorrect id", id, provider.id());
}
......
......@@ -11,8 +11,9 @@ public class ProviderIdTest {
@Test
public void basics() {
new EqualsTester()
.addEqualityGroup(new ProviderId("foo"), new ProviderId("foo"))
.addEqualityGroup(new ProviderId("bar"))
.addEqualityGroup(new ProviderId("of", "foo"), new ProviderId("of", "foo"))
.addEqualityGroup(new ProviderId("snmp", "foo"), new ProviderId("snmp", "foo"))
.addEqualityGroup(new ProviderId("of", "bar"))
.testEquals();
}
......
......@@ -17,7 +17,6 @@ import org.onlab.onos.event.EventDeliveryService;
import org.onlab.onos.net.Device;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.device.DeviceService;
import org.onlab.onos.net.flow.FlowEntry;
import org.onlab.onos.net.flow.FlowRule;
import org.onlab.onos.net.flow.FlowRuleEvent;
import org.onlab.onos.net.flow.FlowRuleListener;
......@@ -62,13 +61,13 @@ implements FlowRuleService, FlowRuleProviderRegistry {
}
@Override
public Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) {
public Iterable<FlowRule> getFlowEntries(DeviceId deviceId) {
return store.getFlowEntries(deviceId);
}
@Override
public List<FlowEntry> applyFlowRules(FlowRule... flowRules) {
List<FlowEntry> entries = new ArrayList<FlowEntry>();
public List<FlowRule> applyFlowRules(FlowRule... flowRules) {
List<FlowRule> entries = new ArrayList<FlowRule>();
for (int i = 0; i < flowRules.length; i++) {
FlowRule f = flowRules[i];
......@@ -159,7 +158,7 @@ implements FlowRuleService, FlowRuleProviderRegistry {
}
@Override
public void pushFlowMetrics(Iterable<FlowEntry> flowEntries) {
public void pushFlowMetrics(Iterable<FlowRule> flowEntries) {
// TODO Auto-generated method stub
}
......
package org.onlab.onos.net.trivial.flow.impl;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.flow.DefaultFlowEntry;
import org.onlab.onos.net.flow.FlowEntry;
import org.onlab.onos.net.flow.DefaultFlowRule;
import org.onlab.onos.net.flow.FlowRule;
import org.onlab.onos.net.flow.FlowRuleEvent;
......@@ -18,7 +17,7 @@ import static org.onlab.onos.net.flow.FlowRuleEvent.Type.*;
public class SimpleFlowRuleStore {
// store entries as a pile of rules, no info about device tables
private final Multimap<DeviceId, FlowEntry> flowEntries = HashMultimap.create();
private final Multimap<DeviceId, FlowRule> flowEntries = HashMultimap.create();
/**
* Returns the flow entries associated with a device.
......@@ -26,19 +25,19 @@ public class SimpleFlowRuleStore {
* @param deviceId the device ID
* @return the flow entries
*/
Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) {
Iterable<FlowRule> getFlowEntries(DeviceId deviceId) {
return ImmutableSet.copyOf(flowEntries.get(deviceId));
}
/**
* Stores a new flow rule, and generates a FlowEntry for it.
* Stores a new flow rule, and generates a FlowRule for it.
*
* @param rule the flow rule to add
* @return a flow entry
*/
FlowEntry storeFlowRule(FlowRule rule) {
FlowRule storeFlowRule(FlowRule rule) {
DeviceId did = rule.deviceId();
FlowEntry entry = new DefaultFlowEntry(did,
FlowRule entry = new DefaultFlowRule(did,
rule.selector(), rule.treatment(), rule.priority());
flowEntries.put(did, entry);
return entry;
......@@ -53,20 +52,14 @@ public class SimpleFlowRuleStore {
FlowRuleEvent addOrUpdateFlowRule(FlowRule rule) {
DeviceId did = rule.deviceId();
FlowEntry entry = new DefaultFlowEntry(
did,
rule.selector(),
rule.treatment(),
rule.priority());
// check if this new rule is an update to an existing entry
for (FlowEntry fe : flowEntries.get(did)) {
if (entry.equals(fe)) {
// TODO update the stats on this flowEntry?
for (FlowRule fe : flowEntries.get(did)) {
if (rule.equals(fe)) {
// TODO update the stats on this FlowRule?
return null;
}
}
flowEntries.put(did, entry);
flowEntries.put(did, rule);
return new FlowRuleEvent(RULE_ADDED, rule);
}
......@@ -77,10 +70,8 @@ public class SimpleFlowRuleStore {
*/
FlowRuleEvent removeFlowRule(FlowRule rule) {
FlowEntry rem = new DefaultFlowEntry(rule.deviceId(),
rule.selector(), rule.treatment(), rule.priority());
synchronized (this) {
if (flowEntries.remove(rem.deviceId(), rem)) {
if (flowEntries.remove(rule.deviceId(), rule)) {
return new FlowRuleEvent(RULE_REMOVED, rule);
} else {
return null;
......
......@@ -45,7 +45,7 @@ public class DefaultTopology extends AbstractModel implements Topology {
private static final TarjanGraphSearch<TopologyVertex, TopologyEdge> TARJAN =
new TarjanGraphSearch<>();
private static final ProviderId PID = new ProviderId("org.onlab.onos.net");
private static final ProviderId PID = new ProviderId("core", "org.onlab.onos.net");
private final long time;
private final TopologyGraph graph;
......
......@@ -74,7 +74,7 @@ public class DefaultTopologyProvider extends AbstractProvider
* Creates a provider with the supplier identifier.
*/
public DefaultTopologyProvider() {
super(new ProviderId("org.onlab.onos.provider.topology"));
super(new ProviderId("core", "org.onlab.onos.provider.topology"));
}
@Activate
......
......@@ -45,7 +45,7 @@ public class SimplePathManager implements PathService {
private static final String ELEMENT_ID_NULL = "Element ID cannot be null";
private static final ProviderId PID = new ProviderId("org.onlab.onos.core");
private static final ProviderId PID = new ProviderId("core", "org.onlab.onos.core");
private static final PortNumber P0 = PortNumber.portNumber(0);
private static final EdgeLink NOT_HOST = new NotHost();
......
......@@ -38,7 +38,7 @@ import static org.onlab.onos.net.device.DeviceEvent.Type.*;
*/
public class SimpleDeviceManagerTest {
private static final ProviderId PID = new ProviderId("foo");
private static final ProviderId PID = new ProviderId("of", "foo");
private static final DeviceId DID1 = deviceId("of:foo");
private static final DeviceId DID2 = deviceId("of:bar");
private static final String MFR = "whitebox";
......
......@@ -4,6 +4,8 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_ADDED;
import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_REMOVED;
import java.util.ArrayList;
import java.util.List;
......@@ -21,9 +23,7 @@ import org.onlab.onos.net.Port;
import org.onlab.onos.net.PortNumber;
import org.onlab.onos.net.device.DeviceListener;
import org.onlab.onos.net.device.DeviceService;
import org.onlab.onos.net.flow.DefaultFlowEntry;
import org.onlab.onos.net.flow.DefaultFlowRule;
import org.onlab.onos.net.flow.FlowEntry;
import org.onlab.onos.net.flow.FlowRule;
import org.onlab.onos.net.flow.FlowRuleEvent;
import org.onlab.onos.net.flow.FlowRuleListener;
......@@ -41,14 +41,12 @@ import org.onlab.onos.net.provider.ProviderId;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import static org.onlab.onos.net.flow.FlowRuleEvent.Type.*;
/**
* Test codifying the flow rule service & flow rule provider service contracts.
*/
public class SimpleFlowRuleManagerTest {
private static final ProviderId PID = new ProviderId("foo");
private static final ProviderId PID = new ProviderId("of", "foo");
private static final DeviceId DID = DeviceId.deviceId("of:001");
private static final Device DEV = new DefaultDevice(
PID, DID, Type.SWITCH, "", "", "", "");
......@@ -81,7 +79,7 @@ public class SimpleFlowRuleManagerTest {
public void tearDown() {
registry.unregister(provider);
assertFalse("provider should not be registered",
registry.getProviders().contains(provider.id()));
registry.getProviders().contains(provider.id()));
service.removeListener(listener);
mgr.deactivate();
mgr.eventDispatcher = null;
......@@ -91,7 +89,7 @@ public class SimpleFlowRuleManagerTest {
private FlowRule flowRule(int tsval, int trval) {
TestSelector ts = new TestSelector(tsval);
TestTreatment tr = new TestTreatment(trval);
return new DefaultFlowRule(DID, ts, tr);
return new DefaultFlowRule(DID, ts, tr, 0);
}
private void addFlowRule(int hval) {
......@@ -142,14 +140,14 @@ public class SimpleFlowRuleManagerTest {
FlowRule r3 = flowRule(1, 3);
//current FlowRules always return 0. FlowEntries inherit the value
FlowEntry e1 = new DefaultFlowEntry(DID, ts, r1.treatment(), 0);
FlowEntry e2 = new DefaultFlowEntry(DID, ts, r2.treatment(), 0);
FlowEntry e3 = new DefaultFlowEntry(DID, ts, r3.treatment(), 0);
List<FlowEntry> fel = Lists.newArrayList(e1, e2, e3);
FlowRule e1 = new DefaultFlowRule(DID, ts, r1.treatment(), 0);
FlowRule e2 = new DefaultFlowRule(DID, ts, r2.treatment(), 0);
FlowRule e3 = new DefaultFlowRule(DID, ts, r3.treatment(), 0);
List<FlowRule> fel = Lists.newArrayList(e1, e2, e3);
assertTrue("store should be empty",
Sets.newHashSet(service.getFlowEntries(DID)).isEmpty());
List<FlowEntry> ret = mgr.applyFlowRules(r1, r2, r3);
List<FlowRule> ret = mgr.applyFlowRules(r1, r2, r3);
assertEquals("3 rules should exist", 3, flowCount());
assertTrue("3 entries should result", fel.containsAll(ret));
}
......@@ -255,17 +253,12 @@ public class SimpleFlowRuleManagerTest {
public void removeFlowRule(FlowRule... flowRules) {
}
@Override
public Iterable<FlowEntry> getFlowMetrics(DeviceId deviceId) {
return null;
}
}
private class TestSelector implements TrafficSelector {
//for controlling hashcode uniqueness;
private int testval;
private final int testval;
public TestSelector(int val) {
testval = val;
......@@ -293,7 +286,7 @@ public class SimpleFlowRuleManagerTest {
private class TestTreatment implements TrafficTreatment {
//for controlling hashcode uniqueness;
private int testval;
private final int testval;
public TestTreatment(int val) {
testval = val;
......
......@@ -42,7 +42,7 @@ import static org.onlab.onos.net.host.HostEvent.Type.*;
*/
public class SimpleHostManagerTest {
private static final ProviderId PID = new ProviderId("foo");
private static final ProviderId PID = new ProviderId("of", "foo");
private static final VlanId VLAN1 = VlanId.vlanId((short) 1);
private static final VlanId VLAN2 = VlanId.vlanId((short) 2);
......
......@@ -40,7 +40,7 @@ import static org.onlab.onos.net.link.LinkEvent.Type.*;
*/
public class SimpleLinkManagerTest {
private static final ProviderId PID = new ProviderId("foo");
private static final ProviderId PID = new ProviderId("of", "foo");
private static final DeviceId DID1 = deviceId("of:foo");
private static final DeviceId DID2 = deviceId("of:bar");
private static final DeviceId DID3 = deviceId("of:goo");
......
......@@ -29,7 +29,7 @@ import static org.onlab.onos.net.trivial.topology.impl.SimpleTopologyManagerTest
*/
public class DefaultTopologyTest {
public static final ProviderId PID = new ProviderId("foo.bar");
public static final ProviderId PID = new ProviderId("of", "foo.bar");
public static final DeviceId D1 = deviceId("of:1");
public static final DeviceId D2 = deviceId("of:2");
......
......@@ -43,7 +43,7 @@ import static org.onlab.onos.net.topology.TopologyEvent.Type.TOPOLOGY_CHANGED;
*/
public class SimpleTopologyManagerTest {
private static final ProviderId PID = new ProviderId("foo");
private static final ProviderId PID = new ProviderId("of", "foo");
private SimpleTopologyManager mgr;
......
......@@ -60,7 +60,7 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
* Creates an OpenFlow device provider.
*/
public OpenFlowDeviceProvider() {
super(new ProviderId("org.onlab.onos.provider.openflow"));
super(new ProviderId("of", "org.onlab.onos.provider.openflow"));
}
@Activate
......
......@@ -62,7 +62,7 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr
* Creates an OpenFlow host provider.
*/
public OpenFlowRuleProvider() {
super(new ProviderId("org.onlab.onos.provider.openflow"));
super(new ProviderId("of", "org.onlab.onos.provider.openflow"));
}
@Activate
......@@ -131,11 +131,11 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr
case FLOW_REMOVED:
//TODO: make this better
OFFlowRemoved removed = (OFFlowRemoved) msg;
FlowRule fr = new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)), null, null);
FlowRule fr = new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)), null, null, 0);
providerService.flowRemoved(fr);
break;
case STATS_REPLY:
pushFlowMetrics((OFStatsReply) msg);
pushFlowMetrics(dpid, (OFStatsReply) msg);
break;
case BARRIER_REPLY:
case ERROR:
......@@ -145,18 +145,16 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr
}
private void pushFlowMetrics(OFStatsReply stats) {
private void pushFlowMetrics(Dpid dpid, OFStatsReply stats) {
if (stats.getStatsType() != OFStatsType.FLOW) {
return;
}
final OFFlowStatsReply replies = (OFFlowStatsReply) stats;
final List<FlowRule> entries = Lists.newLinkedList();
for (OFFlowStatsEntry reply : replies.getEntries()) {
entries.add(new FlowRuleBuilder(reply).build());
entries.add(new FlowRuleBuilder(dpid, reply).build());
}
providerService.pushFlowMetrics(entries);
}
}
......
......@@ -61,7 +61,7 @@ public class OpenFlowHostProvider extends AbstractProvider implements HostProvid
* Creates an OpenFlow host provider.
*/
public OpenFlowHostProvider() {
super(new ProviderId("org.onlab.onos.provider.openflow"));
super(new ProviderId("of", "org.onlab.onos.provider.openflow"));
}
@Activate
......
......@@ -55,7 +55,7 @@ public class OpenFlowLinkProvider extends AbstractProvider implements LinkProvid
* Creates an OpenFlow link provider.
*/
public OpenFlowLinkProvider() {
super(new ProviderId("org.onlab.onos.provider.openflow"));
super(new ProviderId("of", "org.onlab.onos.provider.openflow"));
}
@Activate
......
......@@ -48,7 +48,7 @@ public class OpenFlowPacketProvider extends AbstractProvider implements PacketPr
* Creates an OpenFlow link provider.
*/
public OpenFlowPacketProvider() {
super(new ProviderId("org.onlab.onos.provider.openflow"));
super(new ProviderId("of", "org.onlab.onos.provider.openflow"));
}
@Activate
......
......@@ -27,23 +27,37 @@ mkdir bin
# Stage the ONOS admin scripts and patch in Karaf service wrapper extras
cp -r $ONOS_ROOT/tools/package/bin .
cp -r $ONOS_ROOT/tools/package/wrapper/* $KARAF_DIST
cp -r $ONOS_ROOT/tools/package/etc/* $KARAF_DIST/etc
# Stage the ONOS bundles
mkdir -p $KARAF_DIST/system/org/onlab
cp -r $M2_REPO/org/onlab $KARAF_DIST/system/org/
# Wrapper & Cellar Patching ----------------------------------------------------
# Patch the Apache Karaf distribution file to add Cellar features repository
perl -pi.old -e "s|^(featuresRepositories=.*)|\1,mvn:org.apache.karaf.cellar/apache-karaf-cellar/3.0.0/xml/features|" \
$ONOS_STAGE/$KARAF_DIST/etc/org.apache.karaf.features.cfg
# Patch the Apache Karaf distribution file to load ONOS features
perl -pi.old -e 's|^(featuresBoot=.*)|\1,wrapper,cellar|' \
$ONOS_STAGE/$KARAF_DIST/etc/org.apache.karaf.features.cfg
# ONOS Patching ----------------------------------------------------------------
# Patch the Apache Karaf distribution file to add ONOS features repository
perl -pi.old -e "s|^(featuresRepositories=.*)|\1,mvn:org.onlab.onos/onos-features/$ONOS_VERSION/xml/features|" \
$ONOS_STAGE/$KARAF_DIST/etc/org.apache.karaf.features.cfg
# Patch the Apache Karaf distribution file to load ONOS features
perl -pi.old -e 's|^(featuresBoot=.*)|\1,wrapper,onos-api,onos-core,onos-cli,onos-rest,onos-gui,onos-openflow,onos-app-tvue|' \
perl -pi.old -e 's|^(featuresBoot=.*)|\1,onos-api,onos-core,onos-cli,onos-rest,onos-gui,onos-openflow,onos-app-tvue|' \
$ONOS_STAGE/$KARAF_DIST/etc/org.apache.karaf.features.cfg
# Patch the Apache Karaf distribution with ONOS branding bundle
cp $M2_REPO/org/onlab/onos/onos-branding/$ONOS_VERSION/onos-branding-*.jar \
$ONOS_STAGE/$KARAF_DIST/lib
# Now package up the ONOS tar file
cd $ONOS_STAGE_ROOT
COPYFILE_DISABLE=1 tar zcf $ONOS_TAR $ONOS_BITS
......
#!/bin/bash
# ONOS developer BASH profile conveniences
# Simply include in your own .bash_aliases or .bash_profile
# Root of the ONOS source tree
export ONOS_ROOT=${ONOS_ROOT:-~/onos-next}
......@@ -42,6 +43,23 @@ alias docs='open $ONOS_ROOT/target/site/apidocs/index.html'
alias gui='open http://localhost:8181/onos/tvue'
# Test related conveniences
# Default virtual box ONOS instances 1,2 & 3
export OC1="192.168.56.101"
export OC2="192.168.56.102"
export OC3="192.168.56.103"
# Default instance is #1
export OCI="$OC1"
# SSH to a specified ONOS instance
function sshctl {
[ -n "$1" ] && OCI=$1 && shift
ssh -Y sdn@$OCI "$@"
}
# Miscellaneous
function spy {
ps -ef | egrep "$@" | grep -v egrep
......
<?xml version="1.0" encoding="UTF-8"?>
<hazelcast xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-3.2.xsd"
xmlns="http://www.hazelcast.com/schema/config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<group>
<name>onos</name>
<password>rocks</password>
</group>
<management-center enabled="false">http://localhost:8080/mancenter</management-center>
<network>
<port auto-increment="true" port-count="100">5701</port>
<outbound-ports>
<!--
Allowed port range when connecting to other nodes.
0 or * means use system provided port.
-->
<ports>0</ports>
</outbound-ports>
<join>
<multicast enabled="true">
<multicast-group>224.2.2.3</multicast-group>
<multicast-port>54327</multicast-port>
</multicast>
<tcp-ip enabled="false">
<interface>127.0.0.1</interface>
</tcp-ip>
<aws enabled="false">
<access-key>my-access-key</access-key>
<secret-key>my-secret-key</secret-key>
<!--optional, default is us-east-1 -->
<region>us-west-1</region>
<!--optional, default is ec2.amazonaws.com. If set, region shouldn't be set as it will override this property -->
<host-header>ec2.amazonaws.com</host-header>
<!-- optional, only instances belonging to this group will be discovered, default will try all running instances -->
<security-group-name>hazelcast-sg</security-group-name>
<tag-key>type</tag-key>
<tag-value>hz-nodes</tag-value>
</aws>
</join>
<interfaces enabled="true">
<interface>10.1.9.*</interface>
</interfaces>
<ssl enabled="false"/>
<socket-interceptor enabled="false"/>
<symmetric-encryption enabled="false">
<!--
encryption algorithm such as
DES/ECB/PKCS5Padding,
PBEWithMD5AndDES,
AES/CBC/PKCS5Padding,
Blowfish,
DESede
-->
<algorithm>PBEWithMD5AndDES</algorithm>
<!-- salt value to use when generating the secret key -->
<salt>thesalt</salt>
<!-- pass phrase to use when generating the secret key -->
<password>thepass</password>
<!-- iteration count to use when generating the secret key -->
<iteration-count>19</iteration-count>
</symmetric-encryption>
</network>
<partition-group enabled="false"/>
<executor-service>
<pool-size>16</pool-size>
<!-- Queue capacity. 0 means Integer.MAX_VALUE -->
<queue-capacity>0</queue-capacity>
</executor-service>
<queue name="default">
<!--
Maximum size of the queue. When a JVM's local queue size reaches the maximum,
all put/offer operations will get blocked until the queue size
of the JVM goes down below the maximum.
Any integer between 0 and Integer.MAX_VALUE. 0 means
Integer.MAX_VALUE. Default is 0.
-->
<max-size>0</max-size>
<!--
Number of backups. If 1 is set as the backup-count for example,
then all entries of the map will be copied to another JVM for
fail-safety. 0 means no backup.
-->
<backup-count>1</backup-count>
<!--
Number of async backups. 0 means no backup.
-->
<async-backup-count>0</async-backup-count>
<empty-queue-ttl>-1</empty-queue-ttl>
</queue>
<map name="default">
<!--
Data type that will be used for storing recordMap.
Possible values:
BINARY (default): keys and values will be stored as binary data
OBJECT : values will be stored in their object forms
OFFHEAP : values will be stored in non-heap region of JVM
-->
<in-memory-format>BINARY</in-memory-format>
<!--
Number of backups. If 1 is set as the backup-count for example,
then all entries of the map will be copied to another JVM for
fail-safety. 0 means no backup.
-->
<backup-count>1</backup-count>
<!--
Number of async backups. 0 means no backup.
-->
<async-backup-count>0</async-backup-count>
<!--
Maximum number of seconds for each entry to stay in the map. Entries that are
older than <time-to-live-seconds> and not updated for <time-to-live-seconds>
will get automatically evicted from the map.
Any integer between 0 and Integer.MAX_VALUE. 0 means infinite. Default is 0.
-->
<time-to-live-seconds>0</time-to-live-seconds>
<!--
Maximum number of seconds for each entry to stay idle in the map. Entries that are
idle(not touched) for more than <max-idle-seconds> will get
automatically evicted from the map. Entry is touched if get, put or containsKey is called.
Any integer between 0 and Integer.MAX_VALUE. 0 means infinite. Default is 0.
-->
<max-idle-seconds>0</max-idle-seconds>
<!--
Valid values are:
NONE (no eviction),
LRU (Least Recently Used),
LFU (Least Frequently Used).
NONE is the default.
-->
<eviction-policy>NONE</eviction-policy>
<!--
Maximum size of the map. When max size is reached,
map is evicted based on the policy defined.
Any integer between 0 and Integer.MAX_VALUE. 0 means
Integer.MAX_VALUE. Default is 0.
-->
<max-size policy="PER_NODE">0</max-size>
<!--
When max. size is reached, specified percentage of
the map will be evicted. Any integer between 0 and 100.
If 25 is set for example, 25% of the entries will
get evicted.
-->
<eviction-percentage>25</eviction-percentage>
<!--
While recovering from split-brain (network partitioning),
map entries in the small cluster will merge into the bigger cluster
based on the policy set here. When an entry merge into the
cluster, there might an existing entry with the same key already.
Values of these entries might be different for that same key.
Which value should be set for the key? Conflict is resolved by
the policy set here. Default policy is PutIfAbsentMapMergePolicy
There are built-in merge policies such as
com.hazelcast.map.merge.PassThroughMergePolicy; entry will be added if there is no existing entry for the key.
com.hazelcast.map.merge.PutIfAbsentMapMergePolicy ; entry will be added if the merging entry doesn't exist in the cluster.
com.hazelcast.map.merge.HigherHitsMapMergePolicy ; entry with the higher hits wins.
com.hazelcast.map.merge.LatestUpdateMapMergePolicy ; entry with the latest update wins.
-->
<merge-policy>com.hazelcast.map.merge.PassThroughMergePolicy</merge-policy>
</map>
<multimap name="default">
<backup-count>1</backup-count>
<value-collection-type>SET</value-collection-type>
</multimap>
<multimap name="default">
<backup-count>1</backup-count>
<value-collection-type>SET</value-collection-type>
</multimap>
<list name="default">
<backup-count>1</backup-count>
</list>
<set name="default">
<backup-count>1</backup-count>
</set>
<jobtracker name="default">
<max-thread-size>0</max-thread-size>
<!-- Queue size 0 means number of partitions * 2 -->
<queue-size>0</queue-size>
<retry-count>0</retry-count>
<chunk-size>1000</chunk-size>
<communicate-stats>true</communicate-stats>
<topology-changed-strategy>CANCEL_RUNNING_OPERATION</topology-changed-strategy>
</jobtracker>
<semaphore name="default">
<initial-permits>0</initial-permits>
<backup-count>1</backup-count>
<async-backup-count>0</async-backup-count>
</semaphore>
<serialization>
<portable-version>0</portable-version>
</serialization>
<services enable-defaults="true" />
</hazelcast>
#!/bin/bash
#-------------------------------------------------------------------------------
# Monitors remote ONOS log file.
#-------------------------------------------------------------------------------
[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
. $ONOS_ROOT/tools/build/envDefaults
remote=$ONOS_USER@${1:-$OCI}
LOG=$ONOS_INSTALL_DIR/log/karaf.log
ssh $remote "
while true; do
[ ! -f $LOG ] && sleep 2 && continue
tail -n 512 --follow=name $LOG --sleep-interval 2
done
"