Merge branch 'master' of ssh://gerrit.onlab.us:29418/onos-next
diff --git a/apps/ifwd/src/main/java/org/onlab/onos/ifwd/IntentReactiveForwarding.java b/apps/ifwd/src/main/java/org/onlab/onos/ifwd/IntentReactiveForwarding.java
index fded98f..defdf08 100644
--- a/apps/ifwd/src/main/java/org/onlab/onos/ifwd/IntentReactiveForwarding.java
+++ b/apps/ifwd/src/main/java/org/onlab/onos/ifwd/IntentReactiveForwarding.java
@@ -1,12 +1,12 @@
package org.onlab.onos.ifwd;
-import static org.slf4j.LoggerFactory.getLogger;
-
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.ApplicationId;
+import org.onlab.onos.CoreService;
import org.onlab.onos.net.Host;
import org.onlab.onos.net.HostId;
import org.onlab.onos.net.PortNumber;
@@ -16,7 +16,6 @@
import org.onlab.onos.net.flow.TrafficTreatment;
import org.onlab.onos.net.host.HostService;
import org.onlab.onos.net.intent.HostToHostIntent;
-import org.onlab.onos.net.intent.IntentId;
import org.onlab.onos.net.intent.IntentService;
import org.onlab.onos.net.packet.DefaultOutboundPacket;
import org.onlab.onos.net.packet.InboundPacket;
@@ -28,6 +27,8 @@
import org.onlab.packet.Ethernet;
import org.slf4j.Logger;
+import static org.slf4j.LoggerFactory.getLogger;
+
/**
* WORK-IN-PROGRESS: Sample reactive forwarding application using intent framework.
*/
@@ -37,6 +38,9 @@
private final Logger log = getLogger(getClass());
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected CoreService coreService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected TopologyService topologyService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
@@ -49,11 +53,11 @@
protected HostService hostService;
private ReactivePacketProcessor processor = new ReactivePacketProcessor();
-
- private static long intentId = 0x123000;
+ private ApplicationId appId;
@Activate
public void activate() {
+ appId = coreService.registerApplication("org.onlab.onos.ifwd");
packetService.addProcessor(processor, PacketProcessor.ADVISOR_MAX + 2);
log.info("Started");
}
@@ -126,9 +130,8 @@
TrafficSelector selector = DefaultTrafficSelector.builder().build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
- HostToHostIntent intent =
- new HostToHostIntent(new IntentId(intentId++), srcId, dstId,
- selector, treatment);
+ HostToHostIntent intent = new HostToHostIntent(appId, srcId, dstId,
+ selector, treatment);
intentService.submit(intent);
}
diff --git a/apps/sdnip/src/main/java/org/onlab/onos/sdnip/PeerConnectivityManager.java b/apps/sdnip/src/main/java/org/onlab/onos/sdnip/PeerConnectivityManager.java
index 3917f5a..400dba0 100644
--- a/apps/sdnip/src/main/java/org/onlab/onos/sdnip/PeerConnectivityManager.java
+++ b/apps/sdnip/src/main/java/org/onlab/onos/sdnip/PeerConnectivityManager.java
@@ -1,13 +1,11 @@
package org.onlab.onos.sdnip;
-import java.util.List;
-
+import org.onlab.onos.ApplicationId;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.flow.DefaultTrafficSelector;
import org.onlab.onos.net.flow.DefaultTrafficTreatment;
import org.onlab.onos.net.flow.TrafficSelector;
import org.onlab.onos.net.flow.TrafficTreatment;
-import org.onlab.onos.net.intent.IntentId;
import org.onlab.onos.net.intent.IntentService;
import org.onlab.onos.net.intent.PointToPointIntent;
import org.onlab.onos.sdnip.config.BgpPeer;
@@ -22,6 +20,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.util.List;
+
/**
* Manages the connectivity requirements between peers.
*/
@@ -38,11 +38,13 @@
private final InterfaceService interfaceService;
private final IntentService intentService;
- // TODO this sucks.
- private int intentId = 0;
+ private final ApplicationId appId;
- public PeerConnectivityManager(SdnIpConfigService configInfoService,
- InterfaceService interfaceService, IntentService intentService) {
+ public PeerConnectivityManager(ApplicationId appId,
+ SdnIpConfigService configInfoService,
+ InterfaceService interfaceService,
+ IntentService intentService) {
+ this.appId = appId;
this.configInfoService = configInfoService;
this.interfaceService = interfaceService;
this.intentService = intentService;
@@ -53,15 +55,15 @@
if (interfaceService.getInterfaces().isEmpty()) {
log.warn("The interface in configuration file is empty. "
- + "Thus, the SDN-IP application can not be started.");
+ + "Thus, the SDN-IP application can not be started.");
} else if (configInfoService.getBgpPeers().isEmpty()) {
log.warn("The BGP peer in configuration file is empty."
- + "Thus, the SDN-IP application can not be started.");
+ + "Thus, the SDN-IP application can not be started.");
} else if (configInfoService.getBgpSpeakers() == null) {
log.error("The BGP speaker in configuration file is empty. "
- + "Thus, the SDN-IP application can not be started.");
+ + "Thus, the SDN-IP application can not be started.");
return;
}
@@ -80,7 +82,7 @@
for (BgpSpeaker bgpSpeaker : configInfoService.getBgpSpeakers()
.values()) {
log.debug("Start to set up BGP paths for BGP speaker: {}",
- bgpSpeaker);
+ bgpSpeaker);
ConnectPoint bgpdConnectPoint = bgpSpeaker.connectPoint();
List<InterfaceAddress> interfaceAddresses =
@@ -89,14 +91,14 @@
for (BgpPeer bgpPeer : configInfoService.getBgpPeers().values()) {
log.debug("Start to set up BGP paths between BGP speaker: {} "
- + "to BGP peer: {}", bgpSpeaker, bgpPeer);
+ + "to BGP peer: {}", bgpSpeaker, bgpPeer);
Interface peerInterface = interfaceService.getInterface(
bgpPeer.connectPoint());
if (peerInterface == null) {
log.error("Can not find the corresponding Interface from "
- + "configuration for BGP peer {}",
- bgpPeer.ipAddress());
+ + "configuration for BGP peer {}",
+ bgpPeer.ipAddress());
continue;
}
@@ -110,7 +112,7 @@
}
if (bgpdAddress == null) {
log.debug("There is no interface IP address for bgpPeer: {}"
- + " on interface {}", bgpPeer, bgpPeer.connectPoint());
+ + " on interface {}", bgpPeer, bgpPeer.connectPoint());
return;
}
@@ -123,7 +125,7 @@
// TODO: The usage of PacketMatchBuilder will be improved, then we
// only need to new the PacketMatchBuilder once.
// By then, the code here will be improved accordingly.
- TrafficSelector selector = DefaultTrafficSelector.builder()
+ TrafficSelector selector = DefaultTrafficSelector.builder()
.matchEthType(Ethernet.TYPE_IPV4)
.matchIPProtocol(IPv4.PROTOCOL_TCP)
.matchIPSrc(IpPrefix.valueOf(bgpdAddress.toInt(), IPV4_BIT_LENGTH))
@@ -134,13 +136,13 @@
TrafficTreatment treatment = DefaultTrafficTreatment.builder()
.build();
- PointToPointIntent intentMatchDstTcpPort = new PointToPointIntent(
- nextIntentId(), selector, treatment,
- bgpdConnectPoint, bgpdPeerConnectPoint);
+ PointToPointIntent intentMatchDstTcpPort =
+ new PointToPointIntent(appId, selector, treatment,
+ bgpdConnectPoint, bgpdPeerConnectPoint);
intentService.submit(intentMatchDstTcpPort);
log.debug("Submitted BGP path intent matching dst TCP port 179 "
- + "from BGPd {} to peer {}: {}",
- bgpdAddress, bgpdPeerAddress, intentMatchDstTcpPort);
+ + "from BGPd {} to peer {}: {}",
+ bgpdAddress, bgpdPeerAddress, intentMatchDstTcpPort);
// install intent for BGP path from BGPd to BGP peer matching
// source TCP port 179
@@ -152,13 +154,13 @@
.matchTcpSrc(BGP_PORT)
.build();
- PointToPointIntent intentMatchSrcTcpPort = new PointToPointIntent(
- nextIntentId(), selector, treatment,
- bgpdConnectPoint, bgpdPeerConnectPoint);
+ PointToPointIntent intentMatchSrcTcpPort =
+ new PointToPointIntent(appId, selector, treatment,
+ bgpdConnectPoint, bgpdPeerConnectPoint);
intentService.submit(intentMatchSrcTcpPort);
log.debug("Submitted BGP path intent matching src TCP port 179"
- + "from BGPd {} to peer {}: {}",
- bgpdAddress, bgpdPeerAddress, intentMatchSrcTcpPort);
+ + "from BGPd {} to peer {}: {}",
+ bgpdAddress, bgpdPeerAddress, intentMatchSrcTcpPort);
// install intent for reversed BGP path from BGP peer to BGPd
// matching destination TCP port 179
@@ -170,13 +172,13 @@
.matchTcpDst(BGP_PORT)
.build();
- PointToPointIntent reversedIntentMatchDstTcpPort = new PointToPointIntent(
- nextIntentId(), selector, treatment,
- bgpdPeerConnectPoint, bgpdConnectPoint);
+ PointToPointIntent reversedIntentMatchDstTcpPort =
+ new PointToPointIntent(appId, selector, treatment,
+ bgpdPeerConnectPoint, bgpdConnectPoint);
intentService.submit(reversedIntentMatchDstTcpPort);
log.debug("Submitted BGP path intent matching dst TCP port 179"
- + "from BGP peer {} to BGPd {} : {}",
- bgpdPeerAddress, bgpdAddress, reversedIntentMatchDstTcpPort);
+ + "from BGP peer {} to BGPd {} : {}",
+ bgpdPeerAddress, bgpdAddress, reversedIntentMatchDstTcpPort);
// install intent for reversed BGP path from BGP peer to BGPd
// matching source TCP port 179
@@ -188,13 +190,13 @@
.matchTcpSrc(BGP_PORT)
.build();
- PointToPointIntent reversedIntentMatchSrcTcpPort = new PointToPointIntent(
- nextIntentId(), selector, treatment,
- bgpdPeerConnectPoint, bgpdConnectPoint);
+ PointToPointIntent reversedIntentMatchSrcTcpPort =
+ new PointToPointIntent(appId, selector, treatment,
+ bgpdPeerConnectPoint, bgpdConnectPoint);
intentService.submit(reversedIntentMatchSrcTcpPort);
log.debug("Submitted BGP path intent matching src TCP port 179"
- + "from BGP peer {} to BGPd {} : {}",
- bgpdPeerAddress, bgpdAddress, reversedIntentMatchSrcTcpPort);
+ + "from BGP peer {} to BGPd {} : {}",
+ bgpdPeerAddress, bgpdAddress, reversedIntentMatchSrcTcpPort);
}
}
@@ -212,7 +214,7 @@
for (BgpSpeaker bgpSpeaker : configInfoService.getBgpSpeakers()
.values()) {
log.debug("Start to set up ICMP paths for BGP speaker: {}",
- bgpSpeaker);
+ bgpSpeaker);
ConnectPoint bgpdConnectPoint = bgpSpeaker.connectPoint();
List<InterfaceAddress> interfaceAddresses = bgpSpeaker
.interfaceAddresses();
@@ -224,8 +226,8 @@
if (peerInterface == null) {
log.error("Can not find the corresponding Interface from "
- + "configuration for BGP peer {}",
- bgpPeer.ipAddress());
+ + "configuration for BGP peer {}",
+ bgpPeer.ipAddress());
continue;
}
IpAddress bgpdAddress = null;
@@ -239,8 +241,8 @@
}
if (bgpdAddress == null) {
log.debug("There is no IP address for bgpPeer: {} on "
- + "interface port: {}", bgpPeer,
- bgpPeer.connectPoint());
+ + "interface port: {}", bgpPeer,
+ bgpPeer.connectPoint());
return;
}
@@ -258,12 +260,12 @@
TrafficTreatment treatment = DefaultTrafficTreatment.builder()
.build();
- PointToPointIntent intent = new PointToPointIntent(
- nextIntentId(), selector, treatment,
- bgpdConnectPoint, bgpdPeerConnectPoint);
+ PointToPointIntent intent =
+ new PointToPointIntent(appId, selector, treatment,
+ bgpdConnectPoint, bgpdPeerConnectPoint);
intentService.submit(intent);
log.debug("Submitted ICMP path intent from BGPd {} to peer {} :"
- + " {}", bgpdAddress, bgpdPeerAddress, intent);
+ + " {}", bgpdAddress, bgpdPeerAddress, intent);
// install intent for reversed ICMP path from BGP peer to BGPd
selector = DefaultTrafficSelector.builder()
@@ -273,18 +275,15 @@
.matchIPDst(IpPrefix.valueOf(bgpdAddress.toInt(), IPV4_BIT_LENGTH))
.build();
- PointToPointIntent reversedIntent = new PointToPointIntent(
- nextIntentId(), selector, treatment,
- bgpdPeerConnectPoint, bgpdConnectPoint);
+ PointToPointIntent reversedIntent =
+ new PointToPointIntent(appId, selector, treatment,
+ bgpdPeerConnectPoint, bgpdConnectPoint);
intentService.submit(reversedIntent);
log.debug("Submitted ICMP path intent from BGP peer {} to BGPd"
- + " {} : {}",
- bgpdPeerAddress, bgpdAddress, reversedIntent);
+ + " {} : {}",
+ bgpdPeerAddress, bgpdAddress, reversedIntent);
}
}
}
- private IntentId nextIntentId() {
- return new IntentId(intentId++);
- }
}
diff --git a/apps/sdnip/src/main/java/org/onlab/onos/sdnip/Router.java b/apps/sdnip/src/main/java/org/onlab/onos/sdnip/Router.java
index d610361..ca25a76 100644
--- a/apps/sdnip/src/main/java/org/onlab/onos/sdnip/Router.java
+++ b/apps/sdnip/src/main/java/org/onlab/onos/sdnip/Router.java
@@ -1,5 +1,41 @@
package org.onlab.onos.sdnip;
+import com.google.common.base.Objects;
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.Multimaps;
+import com.google.common.collect.SetMultimap;
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import com.googlecode.concurrenttrees.common.KeyValuePair;
+import com.googlecode.concurrenttrees.radix.node.concrete.DefaultByteArrayNodeFactory;
+import com.googlecode.concurrenttrees.radixinverted.ConcurrentInvertedRadixTree;
+import com.googlecode.concurrenttrees.radixinverted.InvertedRadixTree;
+import org.apache.commons.lang3.tuple.Pair;
+import org.onlab.onos.ApplicationId;
+import org.onlab.onos.net.ConnectPoint;
+import org.onlab.onos.net.Host;
+import org.onlab.onos.net.flow.DefaultTrafficSelector;
+import org.onlab.onos.net.flow.DefaultTrafficTreatment;
+import org.onlab.onos.net.flow.TrafficSelector;
+import org.onlab.onos.net.flow.TrafficTreatment;
+import org.onlab.onos.net.flow.criteria.Criteria.IPCriterion;
+import org.onlab.onos.net.flow.criteria.Criterion;
+import org.onlab.onos.net.flow.criteria.Criterion.Type;
+import org.onlab.onos.net.host.HostEvent;
+import org.onlab.onos.net.host.HostListener;
+import org.onlab.onos.net.host.HostService;
+import org.onlab.onos.net.intent.Intent;
+import org.onlab.onos.net.intent.IntentService;
+import org.onlab.onos.net.intent.MultiPointToSinglePointIntent;
+import org.onlab.onos.sdnip.config.BgpPeer;
+import org.onlab.onos.sdnip.config.Interface;
+import org.onlab.onos.sdnip.config.SdnIpConfigService;
+import org.onlab.packet.Ethernet;
+import org.onlab.packet.IpAddress;
+import org.onlab.packet.IpPrefix;
+import org.onlab.packet.MacAddress;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
@@ -15,47 +51,10 @@
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.Semaphore;
-import org.apache.commons.lang3.tuple.Pair;
-import org.onlab.onos.net.ConnectPoint;
-import org.onlab.onos.net.Host;
-import org.onlab.onos.net.flow.DefaultTrafficSelector;
-import org.onlab.onos.net.flow.DefaultTrafficTreatment;
-import org.onlab.onos.net.flow.TrafficSelector;
-import org.onlab.onos.net.flow.TrafficTreatment;
-import org.onlab.onos.net.flow.criteria.Criteria.IPCriterion;
-import org.onlab.onos.net.flow.criteria.Criterion;
-import org.onlab.onos.net.flow.criteria.Criterion.Type;
-import org.onlab.onos.net.host.HostEvent;
-import org.onlab.onos.net.host.HostListener;
-import org.onlab.onos.net.host.HostService;
-import org.onlab.onos.net.intent.Intent;
-import org.onlab.onos.net.intent.IntentId;
-import org.onlab.onos.net.intent.IntentService;
-import org.onlab.onos.net.intent.MultiPointToSinglePointIntent;
-import org.onlab.onos.sdnip.config.BgpPeer;
-import org.onlab.onos.sdnip.config.Interface;
-import org.onlab.onos.sdnip.config.SdnIpConfigService;
-import org.onlab.packet.Ethernet;
-import org.onlab.packet.IpAddress;
-import org.onlab.packet.IpPrefix;
-import org.onlab.packet.MacAddress;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.base.Objects;
-import com.google.common.collect.HashMultimap;
-import com.google.common.collect.Multimaps;
-import com.google.common.collect.SetMultimap;
-import com.google.common.util.concurrent.ThreadFactoryBuilder;
-import com.googlecode.concurrenttrees.common.KeyValuePair;
-import com.googlecode.concurrenttrees.radix.node.concrete.DefaultByteArrayNodeFactory;
-import com.googlecode.concurrenttrees.radixinverted.ConcurrentInvertedRadixTree;
-import com.googlecode.concurrenttrees.radixinverted.InvertedRadixTree;
-
/**
* This class processes BGP route update, translates each update into a intent
* and submits the intent.
- *
+ * <p/>
* TODO: Make it thread-safe.
*/
public class Router implements RouteListener {
@@ -82,8 +81,7 @@
private ExecutorService bgpUpdatesExecutor;
private ExecutorService bgpIntentsSynchronizerExecutor;
- // TODO temporary
- private int intentId = Integer.MAX_VALUE / 2;
+ private final ApplicationId appId;
//
// State to deal with SDN-IP Leader election and pushing Intents
@@ -99,14 +97,15 @@
/**
* Class constructor.
*
- * @param intentService the intent service
- * @param hostService the host service
+ * @param intentService the intent service
+ * @param hostService the host service
* @param configInfoService the configuration service
- * @param interfaceService the interface service
+ * @param interfaceService the interface service
*/
- public Router(IntentService intentService, HostService hostService,
- SdnIpConfigService configInfoService, InterfaceService interfaceService) {
-
+ public Router(ApplicationId appId, IntentService intentService,
+ HostService hostService, SdnIpConfigService configInfoService,
+ InterfaceService interfaceService) {
+ this.appId = appId;
this.intentService = intentService;
this.hostService = hostService;
this.configInfoService = configInfoService;
@@ -123,7 +122,7 @@
new ThreadFactoryBuilder().setNameFormat("bgp-updates-%d").build());
bgpIntentsSynchronizerExecutor = Executors.newSingleThreadExecutor(
new ThreadFactoryBuilder()
- .setNameFormat("bgp-intents-synchronizer-%d").build());
+ .setNameFormat("bgp-intents-synchronizer-%d").build());
this.hostService.addListener(new InternalHostListener());
}
@@ -198,7 +197,7 @@
intentsSynchronizerSemaphore.drainPermits();
} catch (InterruptedException e) {
log.debug("Interrupted while waiting to become " +
- "Intent Synchronization leader");
+ "Intent Synchronization leader");
interrupted = true;
break;
}
@@ -221,15 +220,15 @@
try {
RouteUpdate update = routeUpdates.take();
switch (update.type()) {
- case UPDATE:
- processRouteAdd(update.routeEntry());
- break;
- case DELETE:
- processRouteDelete(update.routeEntry());
- break;
- default:
- log.error("Unknown update Type: {}", update.type());
- break;
+ case UPDATE:
+ processRouteAdd(update.routeEntry());
+ break;
+ case DELETE:
+ processRouteDelete(update.routeEntry());
+ break;
+ default:
+ log.error("Unknown update Type: {}", update.type());
+ break;
}
} catch (InterruptedException e) {
log.debug("Interrupted while taking from updates queue", e);
@@ -257,7 +256,7 @@
log.debug("Syncing SDN-IP Route Intents...");
Map<IpPrefix, MultiPointToSinglePointIntent> fetchedIntents =
- new HashMap<>();
+ new HashMap<>();
//
// Fetch all intents, and classify the Multi-Point-to-Point Intents
@@ -272,7 +271,7 @@
continue;
}
MultiPointToSinglePointIntent mp2pIntent =
- (MultiPointToSinglePointIntent) intent;
+ (MultiPointToSinglePointIntent) intent;
/*Match match = mp2pIntent.getMatch();
if (!(match instanceof PacketMatch)) {
continue;
@@ -309,18 +308,18 @@
// Intent.
//
Collection<Pair<IpPrefix, MultiPointToSinglePointIntent>>
- storeInMemoryIntents = new LinkedList<>();
+ storeInMemoryIntents = new LinkedList<>();
Collection<Pair<IpPrefix, MultiPointToSinglePointIntent>>
- addIntents = new LinkedList<>();
+ addIntents = new LinkedList<>();
Collection<Pair<IpPrefix, MultiPointToSinglePointIntent>>
- deleteIntents = new LinkedList<>();
+ deleteIntents = new LinkedList<>();
for (Map.Entry<IpPrefix, MultiPointToSinglePointIntent> entry :
- pushedRouteIntents.entrySet()) {
+ pushedRouteIntents.entrySet()) {
IpPrefix prefix = entry.getKey();
MultiPointToSinglePointIntent inMemoryIntent =
- entry.getValue();
+ entry.getValue();
MultiPointToSinglePointIntent fetchedIntent =
- fetchedIntents.get(prefix);
+ fetchedIntents.get(prefix);
if (fetchedIntent == null) {
//
@@ -354,7 +353,7 @@
// Any remaining FETCHED Intents have to be deleted/withdrawn
//
for (Map.Entry<IpPrefix, MultiPointToSinglePointIntent> entry :
- fetchedIntents.entrySet()) {
+ fetchedIntents.entrySet()) {
IpPrefix prefix = entry.getKey();
MultiPointToSinglePointIntent fetchedIntent = entry.getValue();
deleteIntents.add(Pair.of(prefix, fetchedIntent));
@@ -368,17 +367,17 @@
// 3. Add intents: check if the leader before each operation
//
for (Pair<IpPrefix, MultiPointToSinglePointIntent> pair :
- storeInMemoryIntents) {
+ storeInMemoryIntents) {
IpPrefix prefix = pair.getLeft();
MultiPointToSinglePointIntent intent = pair.getRight();
log.debug("Intent synchronization: updating in-memory " +
- "Intent for prefix: {}", prefix);
+ "Intent for prefix: {}", prefix);
pushedRouteIntents.put(prefix, intent);
}
//
isActivatedLeader = true; // Allow push of Intents
for (Pair<IpPrefix, MultiPointToSinglePointIntent> pair :
- deleteIntents) {
+ deleteIntents) {
IpPrefix prefix = pair.getLeft();
MultiPointToSinglePointIntent intent = pair.getRight();
if (!isElectedLeader) {
@@ -386,12 +385,12 @@
return;
}
log.debug("Intent synchronization: deleting Intent for " +
- "prefix: {}", prefix);
+ "prefix: {}", prefix);
intentService.withdraw(intent);
}
//
for (Pair<IpPrefix, MultiPointToSinglePointIntent> pair :
- addIntents) {
+ addIntents) {
IpPrefix prefix = pair.getLeft();
MultiPointToSinglePointIntent intent = pair.getRight();
if (!isElectedLeader) {
@@ -399,7 +398,7 @@
return;
}
log.debug("Intent synchronization: adding Intent for " +
- "prefix: {}", prefix);
+ "prefix: {}", prefix);
intentService.submit(intent);
}
if (!isElectedLeader) {
@@ -419,8 +418,8 @@
* false
*/
private boolean compareMultiPointToSinglePointIntents(
- MultiPointToSinglePointIntent intent1,
- MultiPointToSinglePointIntent intent2) {
+ MultiPointToSinglePointIntent intent1,
+ MultiPointToSinglePointIntent intent2) {
/*Match match1 = intent1.getMatch();
Match match2 = intent2.getMatch();
Action action1 = intent1.getAction();
@@ -457,8 +456,8 @@
IpPrefix prefix = routeEntry.prefix();
IpAddress nextHop = null;
RouteEntry foundRouteEntry =
- bgpRoutes.put(RouteEntry.createBinaryString(prefix),
- routeEntry);
+ bgpRoutes.put(RouteEntry.createBinaryString(prefix),
+ routeEntry);
if (foundRouteEntry != null) {
nextHop = foundRouteEntry.nextHop();
}
@@ -500,7 +499,7 @@
// See if we know the MAC address of the next hop
//MacAddress nextHopMacAddress =
- //proxyArp.getMacAddress(routeEntry.getNextHop());
+ //proxyArp.getMacAddress(routeEntry.getNextHop());
MacAddress nextHopMacAddress = null;
Set<Host> hosts = hostService.getHostsByIp(
routeEntry.nextHop().toPrefix());
@@ -526,8 +525,8 @@
* Adds a route intent given a prefix and a next hop IP address. This
* method will find the egress interface for the intent.
*
- * @param prefix IP prefix of the route to add
- * @param nextHopIpAddress IP address of the next hop
+ * @param prefix IP prefix of the route to add
+ * @param nextHopIpAddress IP address of the next hop
* @param nextHopMacAddress MAC address of the next hop
*/
private void addRouteIntentToNextHop(IpPrefix prefix,
@@ -540,14 +539,14 @@
// Route to a peer
log.debug("Route to peer {}", nextHopIpAddress);
BgpPeer peer =
- configInfoService.getBgpPeers().get(nextHopIpAddress);
+ configInfoService.getBgpPeers().get(nextHopIpAddress);
egressInterface =
- interfaceService.getInterface(peer.connectPoint());
+ interfaceService.getInterface(peer.connectPoint());
} else {
// Route to non-peer
log.debug("Route to non-peer {}", nextHopIpAddress);
egressInterface =
- interfaceService.getMatchingInterface(nextHopIpAddress);
+ interfaceService.getMatchingInterface(nextHopIpAddress);
if (egressInterface == null) {
log.warn("No outgoing interface found for {}",
nextHopIpAddress);
@@ -564,17 +563,17 @@
* Intent will match dst IP prefix and rewrite dst MAC address at all other
* border switches, then forward packets according to dst MAC address.
*
- * @param prefix IP prefix from route
- * @param egressInterface egress Interface connected to next hop router
+ * @param prefix IP prefix from route
+ * @param egressInterface egress Interface connected to next hop router
* @param nextHopMacAddress MAC address of next hop router
*/
private void doAddRouteIntent(IpPrefix prefix, Interface egressInterface,
- MacAddress nextHopMacAddress) {
+ MacAddress nextHopMacAddress) {
log.debug("Adding intent for prefix {}, next hop mac {}",
prefix, nextHopMacAddress);
MultiPointToSinglePointIntent pushedIntent =
- pushedRouteIntents.get(prefix);
+ pushedRouteIntents.get(prefix);
// Just for testing.
if (pushedIntent != null) {
@@ -603,14 +602,14 @@
// Rewrite the destination MAC address
//ModifyDstMacAction modifyDstMacAction =
- //new ModifyDstMacAction(nextHopMacAddress);
+ //new ModifyDstMacAction(nextHopMacAddress);
TrafficTreatment treatment = DefaultTrafficTreatment.builder()
.setEthDst(nextHopMacAddress)
.build();
MultiPointToSinglePointIntent intent =
- new MultiPointToSinglePointIntent(nextIntentId(),
- selector, treatment, ingressPorts, egressPort);
+ new MultiPointToSinglePointIntent(appId, selector, treatment,
+ ingressPorts, egressPort);
if (isElectedLeader && isActivatedLeader) {
log.debug("Intent installation: adding Intent for prefix: {}",
@@ -665,11 +664,11 @@
IpPrefix prefix = routeEntry.prefix();
MultiPointToSinglePointIntent intent =
- pushedRouteIntents.remove(prefix);
+ pushedRouteIntents.remove(prefix);
if (intent == null) {
log.debug("There is no intent in pushedRouteIntents to delete " +
- "for prefix: {}", prefix);
+ "for prefix: {}", prefix);
} else {
if (isElectedLeader && isActivatedLeader) {
log.debug("Intent installation: deleting Intent for prefix: {}",
@@ -683,8 +682,8 @@
* This method handles the prefixes which are waiting for ARP replies for
* MAC addresses of next hops.
*
- * @param ipAddress next hop router IP address, for which we sent ARP
- * request out
+ * @param ipAddress next hop router IP address, for which we sent ARP
+ * request out
* @param macAddress MAC address which is relative to the ipAddress
*/
//@Override
@@ -692,22 +691,22 @@
public void arpResponse(IpAddress ipAddress, MacAddress macAddress) {
log.debug("Received ARP response: {} => {}", ipAddress, macAddress);
- // We synchronize on this to prevent changes to the radix tree
- // while we're pushing intents. If the tree changes, the
- // tree and intents could get out of sync.
+ // We synchronize on this to prevent changes to the radix tree
+ // while we're pushing intents. If the tree changes, the
+ // tree and intents could get out of sync.
synchronized (this) {
Set<RouteEntry> routesToPush =
- routesWaitingOnArp.removeAll(ipAddress);
+ routesWaitingOnArp.removeAll(ipAddress);
for (RouteEntry routeEntry : routesToPush) {
// These will always be adds
IpPrefix prefix = routeEntry.prefix();
String binaryString = RouteEntry.createBinaryString(prefix);
RouteEntry foundRouteEntry =
- bgpRoutes.getValueForExactKey(binaryString);
+ bgpRoutes.getValueForExactKey(binaryString);
if (foundRouteEntry != null &&
- foundRouteEntry.nextHop().equals(routeEntry.nextHop())) {
+ foundRouteEntry.nextHop().equals(routeEntry.nextHop())) {
log.debug("Pushing prefix {} next hop {}",
routeEntry.prefix(), routeEntry.nextHop());
// We only push prefix flows if the prefix is still in the
@@ -718,8 +717,8 @@
addRouteIntentToNextHop(prefix, ipAddress, macAddress);
} else {
log.debug("Received ARP response, but {}/{} is no longer in"
- + " the radix tree", routeEntry.prefix(),
- routeEntry.nextHop());
+ + " the radix tree", routeEntry.prefix(),
+ routeEntry.nextHop());
}
}
}
@@ -745,15 +744,6 @@
}
/**
- * Generates a new unique intent ID.
- *
- * @return the new intent ID.
- */
- private IntentId nextIntentId() {
- return new IntentId(intentId++);
- }
-
- /**
* Listener for host events.
*/
class InternalHostListener implements HostListener {
diff --git a/apps/sdnip/src/main/java/org/onlab/onos/sdnip/SdnIp.java b/apps/sdnip/src/main/java/org/onlab/onos/sdnip/SdnIp.java
index 529e60a..54aa9e5 100644
--- a/apps/sdnip/src/main/java/org/onlab/onos/sdnip/SdnIp.java
+++ b/apps/sdnip/src/main/java/org/onlab/onos/sdnip/SdnIp.java
@@ -10,6 +10,8 @@
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
+import org.onlab.onos.ApplicationId;
+import org.onlab.onos.CoreService;
import org.onlab.onos.net.host.HostService;
import org.onlab.onos.net.intent.IntentService;
import org.onlab.onos.sdnip.bgp.BgpRouteEntry;
@@ -24,9 +26,14 @@
@Service
public class SdnIp implements SdnIpService {
+ private static final String SDN_ID_APP = "org.onlab.onos.sdnip";
+
private final Logger log = getLogger(getClass());
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected CoreService coreService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected IntentService intentService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
@@ -46,10 +53,11 @@
InterfaceService interfaceService = new HostToInterfaceAdaptor(hostService);
- peerConnectivity = new PeerConnectivityManager(config, interfaceService, intentService);
+ ApplicationId appId = coreService.registerApplication(SDN_ID_APP);
+ peerConnectivity = new PeerConnectivityManager(appId, config, interfaceService, intentService);
peerConnectivity.start();
- router = new Router(intentService, hostService, config, interfaceService);
+ router = new Router(appId, intentService, hostService, config, interfaceService);
router.start();
bgpSessionManager = new BgpSessionManager(router);
diff --git a/apps/sdnip/src/test/java/org/onlab/onos/sdnip/PeerConnectivityManagerTest.java b/apps/sdnip/src/test/java/org/onlab/onos/sdnip/PeerConnectivityManagerTest.java
index 0ecea00..962a6ec 100644
--- a/apps/sdnip/src/test/java/org/onlab/onos/sdnip/PeerConnectivityManagerTest.java
+++ b/apps/sdnip/src/test/java/org/onlab/onos/sdnip/PeerConnectivityManagerTest.java
@@ -1,23 +1,11 @@
package org.onlab.onos.sdnip;
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.reportMatcher;
-import static org.easymock.EasyMock.reset;
-import static org.easymock.EasyMock.verify;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
+import com.google.common.collect.Sets;
import org.easymock.IArgumentMatcher;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
+import org.onlab.onos.ApplicationId;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.PortNumber;
@@ -25,7 +13,6 @@
import org.onlab.onos.net.flow.DefaultTrafficTreatment;
import org.onlab.onos.net.flow.TrafficSelector;
import org.onlab.onos.net.flow.TrafficTreatment;
-import org.onlab.onos.net.intent.IntentId;
import org.onlab.onos.net.intent.IntentService;
import org.onlab.onos.net.intent.PointToPointIntent;
import org.onlab.onos.sdnip.bgp.BgpConstants;
@@ -40,13 +27,32 @@
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
-import com.google.common.collect.Sets;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import static org.easymock.EasyMock.*;
/**
* Unit tests for PeerConnectivityManager interface.
*/
public class PeerConnectivityManagerTest {
+ private static final ApplicationId APPID = new ApplicationId() {
+ @Override
+ public short id() {
+ return 0;
+ }
+
+ @Override
+ public String name() {
+ return "foo";
+ }
+ };
+
private PeerConnectivityManager peerConnectivityManager;
private IntentService intentService;
private SdnIpConfigService configInfoService;
@@ -81,9 +87,6 @@
private final ConnectPoint s2Eth1 =
new ConnectPoint(deviceId2, PortNumber.portNumber(1));
- // We don't compare the intent ID so all expected intents can use the same ID
- private final IntentId testIntentId = new IntentId(0);
-
private final TrafficTreatment noTreatment =
DefaultTrafficTreatment.builder().build();
@@ -257,7 +260,7 @@
}
PointToPointIntent intent = new PointToPointIntent(
- testIntentId, builder.build(), noTreatment,
+ APPID, builder.build(), noTreatment,
srcConnectPoint, dstConnectPoint);
intentList.add(intent);
@@ -429,7 +432,7 @@
.build();
PointToPointIntent intent = new PointToPointIntent(
- testIntentId, selector, noTreatment,
+ APPID, selector, noTreatment,
srcConnectPoint, dstConnectPoint);
intentList.add(intent);
@@ -511,7 +514,7 @@
intentService = createMock(IntentService.class);
replay(intentService);
- peerConnectivityManager = new PeerConnectivityManager(configInfoService,
+ peerConnectivityManager = new PeerConnectivityManager(APPID, configInfoService,
interfaceService, intentService);
}
@@ -557,7 +560,7 @@
providedIntentString = providedIntent.toString();
PointToPointIntent matchIntent =
- new PointToPointIntent(providedIntent.id(),
+ new PointToPointIntent(providedIntent.appId(),
intent.selector(), intent.treatment(),
intent.ingressPoint(), intent.egressPoint());
diff --git a/cli/src/main/java/org/onlab/onos/cli/AbstractShellCommand.java b/cli/src/main/java/org/onlab/onos/cli/AbstractShellCommand.java
index 839d2841..5c68a22 100644
--- a/cli/src/main/java/org/onlab/onos/cli/AbstractShellCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/AbstractShellCommand.java
@@ -2,6 +2,8 @@
import org.apache.karaf.shell.commands.Option;
import org.apache.karaf.shell.console.OsgiCommandSupport;
+import org.onlab.onos.ApplicationId;
+import org.onlab.onos.CoreService;
import org.onlab.osgi.DefaultServiceDirectory;
import org.onlab.osgi.ServiceNotFoundException;
@@ -27,6 +29,15 @@
}
/**
+ * Returns application ID for the CLI.
+ *
+ * @return command-line application identifier
+ */
+ protected ApplicationId appId() {
+ return get(CoreService.class).registerApplication("org.onlab.onos.cli");
+ }
+
+ /**
* Prints the arguments using the specified format.
*
* @param format format string; see {@link String#format}
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/AddHostToHostIntentCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/AddHostToHostIntentCommand.java
index 837a0a7..5a75a17 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/AddHostToHostIntentCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/AddHostToHostIntentCommand.java
@@ -9,7 +9,6 @@
import org.onlab.onos.net.flow.TrafficSelector;
import org.onlab.onos.net.flow.TrafficTreatment;
import org.onlab.onos.net.intent.HostToHostIntent;
-import org.onlab.onos.net.intent.IntentId;
import org.onlab.onos.net.intent.IntentService;
/**
@@ -27,8 +26,6 @@
required = true, multiValued = false)
String two = null;
- private static long id = 0x7870001;
-
@Override
protected void execute() {
IntentService service = get(IntentService.class);
@@ -39,9 +36,8 @@
TrafficSelector selector = DefaultTrafficSelector.builder().build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
- HostToHostIntent intent =
- new HostToHostIntent(new IntentId(id++), oneId, twoId,
- selector, treatment);
+ HostToHostIntent intent = new HostToHostIntent(appId(), oneId, twoId,
+ selector, treatment);
service.submit(intent);
}
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/AddMultiPointToSinglePointIntentCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/AddMultiPointToSinglePointIntentCommand.java
index cdae8a6..56bbdaf 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/AddMultiPointToSinglePointIntentCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/AddMultiPointToSinglePointIntentCommand.java
@@ -1,8 +1,5 @@
package org.onlab.onos.cli.net;
-import java.util.HashSet;
-import java.util.Set;
-
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.onlab.onos.cli.AbstractShellCommand;
@@ -14,11 +11,16 @@
import org.onlab.onos.net.flow.TrafficSelector;
import org.onlab.onos.net.flow.TrafficTreatment;
import org.onlab.onos.net.intent.Intent;
-import org.onlab.onos.net.intent.IntentId;
import org.onlab.onos.net.intent.IntentService;
import org.onlab.onos.net.intent.MultiPointToSinglePointIntent;
import org.onlab.packet.Ethernet;
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.onlab.onos.net.DeviceId.deviceId;
+import static org.onlab.onos.net.PortNumber.portNumber;
+
/**
* Installs point-to-point connectivity intents.
*/
@@ -31,8 +33,6 @@
required = true, multiValued = true)
String[] deviceStrings = null;
- private static long id = 0x7070001;
-
@Override
protected void execute() {
IntentService service = get(IntentService.class);
@@ -42,33 +42,26 @@
}
String egressDeviceString = deviceStrings[deviceStrings.length - 1];
- DeviceId egressDeviceId = DeviceId.deviceId(getDeviceId(egressDeviceString));
- PortNumber egressPortNumber =
- PortNumber.portNumber(getPortNumber(egressDeviceString));
+ DeviceId egressDeviceId = deviceId(getDeviceId(egressDeviceString));
+ PortNumber egressPortNumber = portNumber(getPortNumber(egressDeviceString));
ConnectPoint egress = new ConnectPoint(egressDeviceId, egressPortNumber);
Set<ConnectPoint> ingressPoints = new HashSet<>();
for (int index = 0; index < deviceStrings.length - 1; index++) {
String ingressDeviceString = deviceStrings[index];
- DeviceId ingressDeviceId = DeviceId.deviceId(getDeviceId(ingressDeviceString));
- PortNumber ingressPortNumber =
- PortNumber.portNumber(getPortNumber(ingressDeviceString));
+ DeviceId ingressDeviceId = deviceId(getDeviceId(ingressDeviceString));
+ PortNumber ingressPortNumber = portNumber(getPortNumber(ingressDeviceString));
ConnectPoint ingress = new ConnectPoint(ingressDeviceId, ingressPortNumber);
ingressPoints.add(ingress);
}
-
TrafficSelector selector = DefaultTrafficSelector.builder()
.matchEthType(Ethernet.TYPE_IPV4)
.build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
- Intent intent =
- new MultiPointToSinglePointIntent(new IntentId(id++),
- selector,
- treatment,
- ingressPoints,
- egress);
+ Intent intent = new MultiPointToSinglePointIntent(appId(), selector, treatment,
+ ingressPoints, egress);
service.submit(intent);
}
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/AddPointToPointIntentCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/AddPointToPointIntentCommand.java
index 89ec7f6..bd24366 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/AddPointToPointIntentCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/AddPointToPointIntentCommand.java
@@ -11,11 +11,13 @@
import org.onlab.onos.net.flow.TrafficSelector;
import org.onlab.onos.net.flow.TrafficTreatment;
import org.onlab.onos.net.intent.Intent;
-import org.onlab.onos.net.intent.IntentId;
import org.onlab.onos.net.intent.IntentService;
import org.onlab.onos.net.intent.PointToPointIntent;
import org.onlab.packet.Ethernet;
+import static org.onlab.onos.net.DeviceId.deviceId;
+import static org.onlab.onos.net.PortNumber.portNumber;
+
/**
* Installs point-to-point connectivity intents.
*/
@@ -33,20 +35,16 @@
required = true, multiValued = false)
String egressDeviceString = null;
- private static long id = 0x7470001;
-
@Override
protected void execute() {
IntentService service = get(IntentService.class);
- DeviceId ingressDeviceId = DeviceId.deviceId(getDeviceId(ingressDeviceString));
- PortNumber ingressPortNumber =
- PortNumber.portNumber(getPortNumber(ingressDeviceString));
+ DeviceId ingressDeviceId = deviceId(getDeviceId(ingressDeviceString));
+ PortNumber ingressPortNumber = portNumber(getPortNumber(ingressDeviceString));
ConnectPoint ingress = new ConnectPoint(ingressDeviceId, ingressPortNumber);
- DeviceId egressDeviceId = DeviceId.deviceId(getDeviceId(egressDeviceString));
- PortNumber egressPortNumber =
- PortNumber.portNumber(getPortNumber(egressDeviceString));
+ DeviceId egressDeviceId = deviceId(getDeviceId(egressDeviceString));
+ PortNumber egressPortNumber = portNumber(getPortNumber(egressDeviceString));
ConnectPoint egress = new ConnectPoint(egressDeviceId, egressPortNumber);
TrafficSelector selector = DefaultTrafficSelector.builder()
@@ -54,12 +52,8 @@
.build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
- Intent intent =
- new PointToPointIntent(new IntentId(id++),
- selector,
- treatment,
- ingress,
- egress);
+ Intent intent = new PointToPointIntent(appId(), selector, treatment,
+ ingress, egress);
service.submit(intent);
}
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/IntentPushTestCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/IntentPushTestCommand.java
index 4c3ed8e..bd010ae 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/IntentPushTestCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/IntentPushTestCommand.java
@@ -1,8 +1,5 @@
package org.onlab.onos.cli.net;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.onlab.onos.cli.AbstractShellCommand;
@@ -16,20 +13,25 @@
import org.onlab.onos.net.intent.Intent;
import org.onlab.onos.net.intent.IntentEvent;
import org.onlab.onos.net.intent.IntentEvent.Type;
-import org.onlab.onos.net.intent.IntentId;
import org.onlab.onos.net.intent.IntentListener;
import org.onlab.onos.net.intent.IntentService;
import org.onlab.onos.net.intent.PointToPointIntent;
import org.onlab.packet.Ethernet;
import org.onlab.packet.MacAddress;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import static org.onlab.onos.net.DeviceId.deviceId;
+import static org.onlab.onos.net.PortNumber.portNumber;
+
/**
* Installs point-to-point connectivity intents.
*/
@Command(scope = "onos", name = "push-test-intents",
description = "Installs random intents to test throughput")
public class IntentPushTestCommand extends AbstractShellCommand
- implements IntentListener {
+ implements IntentListener {
@Argument(index = 0, name = "ingressDevice",
description = "Ingress Device/Port Description",
@@ -42,8 +44,8 @@
String egressDeviceString = null;
@Argument(index = 2, name = "count",
- description = "Number of intents to push",
- required = true, multiValued = false)
+ description = "Number of intents to push",
+ required = true, multiValued = false)
String countString = null;
@@ -57,14 +59,12 @@
protected void execute() {
service = get(IntentService.class);
- DeviceId ingressDeviceId = DeviceId.deviceId(getDeviceId(ingressDeviceString));
- PortNumber ingressPortNumber =
- PortNumber.portNumber(getPortNumber(ingressDeviceString));
+ DeviceId ingressDeviceId = deviceId(getDeviceId(ingressDeviceString));
+ PortNumber ingressPortNumber = portNumber(getPortNumber(ingressDeviceString));
ConnectPoint ingress = new ConnectPoint(ingressDeviceId, ingressPortNumber);
- DeviceId egressDeviceId = DeviceId.deviceId(getDeviceId(egressDeviceString));
- PortNumber egressPortNumber =
- PortNumber.portNumber(getPortNumber(egressDeviceString));
+ DeviceId egressDeviceId = deviceId(getDeviceId(egressDeviceString));
+ PortNumber egressPortNumber = portNumber(getPortNumber(egressDeviceString));
ConnectPoint egress = new ConnectPoint(egressDeviceId, egressPortNumber);
TrafficSelector.Builder selector = DefaultTrafficSelector.builder()
@@ -79,14 +79,10 @@
start = System.currentTimeMillis();
for (int i = 0; i < count; i++) {
TrafficSelector s = selector
- .matchEthSrc(MacAddress.valueOf(i))
- .build();
- Intent intent =
- new PointToPointIntent(new IntentId(id++),
- s,
- treatment,
- ingress,
- egress);
+ .matchEthSrc(MacAddress.valueOf(i))
+ .build();
+ Intent intent = new PointToPointIntent(appId(), s, treatment,
+ ingress, egress);
service.submit(intent);
}
try {
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/IntentRemoveCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/IntentRemoveCommand.java
index 7684da4..df5f335 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/IntentRemoveCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/IntentRemoveCommand.java
@@ -7,6 +7,8 @@
import org.onlab.onos.net.intent.IntentId;
import org.onlab.onos.net.intent.IntentService;
+import java.math.BigInteger;
+
/**
* Removes host-to-host connectivity intent.
*/
@@ -22,13 +24,11 @@
protected void execute() {
IntentService service = get(IntentService.class);
- int radix = id.startsWith("0x") ? 16 : 10;
- if (radix == 16) {
+ if (id.startsWith("0x")) {
id = id.replaceFirst("0x", "");
}
- IntentId intentId = new IntentId(Long.parseLong(id, radix));
-
+ IntentId intentId = IntentId.valueOf(new BigInteger(id, 16).longValue());
Intent intent = service.getIntent(intentId);
if (intent != null) {
service.withdraw(intent);
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/IntentsListCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/IntentsListCommand.java
index a0c9845..e200cd0 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/IntentsListCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/IntentsListCommand.java
@@ -18,7 +18,8 @@
IntentService service = get(IntentService.class);
for (Intent intent : service.getIntents()) {
IntentState state = service.getIntentState(intent.id());
- print("%s %s %s", intent.id(), state, intent);
+ print("id=%s, state=%s, appId=%s, %s",
+ intent.id(), state, intent.appId().name(), intent);
}
}
diff --git a/core/api/src/main/java/org/onlab/onos/cluster/RoleInfo.java b/core/api/src/main/java/org/onlab/onos/cluster/RoleInfo.java
index bf7442e..45b96ab 100644
--- a/core/api/src/main/java/org/onlab/onos/cluster/RoleInfo.java
+++ b/core/api/src/main/java/org/onlab/onos/cluster/RoleInfo.java
@@ -1,11 +1,9 @@
package org.onlab.onos.cluster;
-import java.util.Collections;
-import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
-import static com.google.common.base.Preconditions.checkNotNull;
+import com.google.common.collect.ImmutableList;
/**
* A container for detailed role information for a device,
@@ -18,9 +16,7 @@
public RoleInfo(NodeId master, List<NodeId> backups) {
this.master = master;
- this.backups = new LinkedList<>();
-
- this.backups.addAll(checkNotNull(backups));
+ this.backups = ImmutableList.copyOf(backups);
}
public NodeId master() {
@@ -28,7 +24,7 @@
}
public List<NodeId> backups() {
- return Collections.unmodifiableList(backups);
+ return backups;
}
@Override
@@ -57,10 +53,10 @@
@Override
public String toString() {
final StringBuilder builder = new StringBuilder();
- builder.append("master: \n\t").append(master).append("\n");
- builder.append("backups: \n");
+ builder.append("master:").append(master).append(",");
+ builder.append("backups:");
for (NodeId n : backups) {
- builder.append("\t").append(n).append("\n");
+ builder.append(" ").append(n);
}
return builder.toString();
}
diff --git a/core/api/src/main/java/org/onlab/onos/net/Link.java b/core/api/src/main/java/org/onlab/onos/net/Link.java
index be2f99bf..1ae5b9d 100644
--- a/core/api/src/main/java/org/onlab/onos/net/Link.java
+++ b/core/api/src/main/java/org/onlab/onos/net/Link.java
@@ -3,7 +3,7 @@
/**
* Abstraction of a network infrastructure link.
*/
-public interface Link extends Annotated, Provided {
+public interface Link extends Annotated, Provided, NetworkResource {
/**
* Coarse representation of the link type.
diff --git a/core/api/src/main/java/org/onlab/onos/net/flow/DefaultTrafficSelector.java b/core/api/src/main/java/org/onlab/onos/net/flow/DefaultTrafficSelector.java
index a388b48..f51d75e 100644
--- a/core/api/src/main/java/org/onlab/onos/net/flow/DefaultTrafficSelector.java
+++ b/core/api/src/main/java/org/onlab/onos/net/flow/DefaultTrafficSelector.java
@@ -8,7 +8,6 @@
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
-import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
@@ -27,7 +26,7 @@
* @param criteria criteria
*/
private DefaultTrafficSelector(Set<Criterion> criteria) {
- this.criteria = Collections.unmodifiableSet(criteria);
+ this.criteria = ImmutableSet.copyOf(criteria);
}
@Override
diff --git a/core/api/src/main/java/org/onlab/onos/net/flow/DefaultTrafficTreatment.java b/core/api/src/main/java/org/onlab/onos/net/flow/DefaultTrafficTreatment.java
index 269347a..d202217 100644
--- a/core/api/src/main/java/org/onlab/onos/net/flow/DefaultTrafficTreatment.java
+++ b/core/api/src/main/java/org/onlab/onos/net/flow/DefaultTrafficTreatment.java
@@ -7,7 +7,8 @@
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
-import java.util.Collections;
+import com.google.common.collect.ImmutableList;
+
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
@@ -25,7 +26,7 @@
* @param instructions treatment instructions
*/
private DefaultTrafficTreatment(List<Instruction> instructions) {
- this.instructions = Collections.unmodifiableList(instructions);
+ this.instructions = ImmutableList.copyOf(instructions);
}
@Override
diff --git a/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleEvent.java b/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleEvent.java
index b17449d..97efa5a 100644
--- a/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleEvent.java
+++ b/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleEvent.java
@@ -24,7 +24,18 @@
/**
* Signifies that a rule has been updated.
*/
- RULE_UPDATED
+ RULE_UPDATED,
+
+ // internal event between Manager <-> Store
+
+ /*
+ * Signifies that a request to add flow rule has been added to the store.
+ */
+ RULE_ADD_REQUESTED,
+ /*
+ * Signifies that a request to remove flow rule has been added to the store.
+ */
+ RULE_REMOVE_REQUESTED,
}
/**
diff --git a/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleStore.java b/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleStore.java
index 5ce7eb1..abb9a10 100644
--- a/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleStore.java
+++ b/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleStore.java
@@ -44,16 +44,18 @@
* Stores a new flow rule without generating events.
*
* @param rule the flow rule to add
+ * @return true if the rule should be handled locally
*/
- void storeFlowRule(FlowRule rule);
+ boolean storeFlowRule(FlowRule rule);
/**
* Marks a flow rule for deletion. Actual deletion will occur
* when the provider indicates that the flow has been removed.
*
* @param rule the flow rule to delete
+ * @return true if the rule should be handled locally
*/
- void deleteFlowRule(FlowRule rule);
+ boolean deleteFlowRule(FlowRule rule);
/**
* Stores a new flow rule, or updates an existing entry.
diff --git a/core/api/src/main/java/org/onlab/onos/net/intent/AbstractIntent.java b/core/api/src/main/java/org/onlab/onos/net/intent/AbstractIntent.java
deleted file mode 100644
index c8a4a05..0000000
--- a/core/api/src/main/java/org/onlab/onos/net/intent/AbstractIntent.java
+++ /dev/null
@@ -1,49 +0,0 @@
-package org.onlab.onos.net.intent;
-
-/**
- * Base intent implementation.
- */
-public abstract class AbstractIntent implements Intent {
-
- private final IntentId id;
-
- /**
- * Creates a base intent with the specified identifier.
- *
- * @param id intent identifier
- */
- protected AbstractIntent(IntentId id) {
- this.id = id;
- }
-
- /**
- * Constructor for serializer.
- */
- protected AbstractIntent() {
- this.id = null;
- }
-
- @Override
- public IntentId id() {
- return id;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
-
- AbstractIntent that = (AbstractIntent) o;
- return id.equals(that.id);
- }
-
- @Override
- public int hashCode() {
- return id.hashCode();
- }
-
-}
diff --git a/core/api/src/main/java/org/onlab/onos/net/intent/ConnectivityIntent.java b/core/api/src/main/java/org/onlab/onos/net/intent/ConnectivityIntent.java
index ed0c5cc..8d634a4 100644
--- a/core/api/src/main/java/org/onlab/onos/net/intent/ConnectivityIntent.java
+++ b/core/api/src/main/java/org/onlab/onos/net/intent/ConnectivityIntent.java
@@ -1,15 +1,20 @@
package org.onlab.onos.net.intent;
-import com.google.common.base.Objects;
+import com.google.common.collect.ImmutableSet;
+import org.onlab.onos.ApplicationId;
+import org.onlab.onos.net.Link;
+import org.onlab.onos.net.NetworkResource;
import org.onlab.onos.net.flow.TrafficSelector;
import org.onlab.onos.net.flow.TrafficTreatment;
+import java.util.Collection;
+
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Abstraction of connectivity intent for traffic matching some criteria.
*/
-public abstract class ConnectivityIntent extends AbstractIntent {
+public abstract class ConnectivityIntent extends Intent {
// TODO: other forms of intents should be considered for this family:
// point-to-point with constraints (waypoints/obstacles)
@@ -19,24 +24,26 @@
// ...
private final TrafficSelector selector;
- // TODO: should consider which is better for multiple actions,
- // defining compound action class or using list of actions.
private final TrafficTreatment treatment;
/**
- * Creates a connectivity intent that matches on the specified intent
- * and applies the specified treatement.
+ * Creates a connectivity intent that matches on the specified selector
+ * and applies the specified treatment.
*
- * @param intentId intent identifier
- * @param selector traffic selector
- * @param treatement treatement
+ * @param id intent identifier
+ * @param appId application identifier
+ * @param resources required network resources (optional)
+ * @param selector traffic selector
+ * @param treatment treatment
* @throws NullPointerException if the selector or treatement is null
*/
- protected ConnectivityIntent(IntentId intentId, TrafficSelector selector,
- TrafficTreatment treatement) {
- super(intentId);
+ protected ConnectivityIntent(IntentId id, ApplicationId appId,
+ Collection<NetworkResource> resources,
+ TrafficSelector selector,
+ TrafficTreatment treatment) {
+ super(id, appId, resources);
this.selector = checkNotNull(selector);
- this.treatment = checkNotNull(treatement);
+ this.treatment = checkNotNull(treatment);
}
/**
@@ -66,19 +73,14 @@
return treatment;
}
- @Override
- public boolean equals(Object o) {
- if (!super.equals(o)) {
- return false;
- }
- ConnectivityIntent that = (ConnectivityIntent) o;
- return Objects.equal(this.selector, that.selector)
- && Objects.equal(this.treatment, that.treatment);
- }
-
- @Override
- public int hashCode() {
- return Objects.hashCode(super.hashCode(), selector, treatment);
+ /**
+ * Produces a collection of network resources from the given links.
+ *
+ * @param links collection of links
+ * @return collection of link resources
+ */
+ protected static Collection<NetworkResource> resources(Collection<Link> links) {
+ return ImmutableSet.<NetworkResource>copyOf(links);
}
}
diff --git a/core/api/src/main/java/org/onlab/onos/net/intent/HostToHostIntent.java b/core/api/src/main/java/org/onlab/onos/net/intent/HostToHostIntent.java
index 7a894be6..83fe92a 100644
--- a/core/api/src/main/java/org/onlab/onos/net/intent/HostToHostIntent.java
+++ b/core/api/src/main/java/org/onlab/onos/net/intent/HostToHostIntent.java
@@ -1,12 +1,11 @@
package org.onlab.onos.net.intent;
import com.google.common.base.MoreObjects;
+import org.onlab.onos.ApplicationId;
import org.onlab.onos.net.HostId;
import org.onlab.onos.net.flow.TrafficSelector;
import org.onlab.onos.net.flow.TrafficTreatment;
-import java.util.Objects;
-
import static com.google.common.base.Preconditions.checkNotNull;
/**
@@ -18,25 +17,33 @@
private final HostId two;
/**
- * Creates a new point-to-point intent with the supplied ingress/egress
- * ports.
+ * Creates a new host-to-host intent with the supplied host pair.
*
- * @param intentId intent identifier
+ * @param appId application identifier
* @param one first host
* @param two second host
* @param selector action
* @param treatment ingress port
- * @throws NullPointerException if {@code ingressPort} or {@code egressPort}
- * is null.
+ * @throws NullPointerException if {@code one} or {@code two} is null.
*/
- public HostToHostIntent(IntentId intentId, HostId one, HostId two,
+ public HostToHostIntent(ApplicationId appId, HostId one, HostId two,
TrafficSelector selector,
TrafficTreatment treatment) {
- super(intentId, selector, treatment);
+ super(id(HostToHostIntent.class, min(one, two), max(one, two),
+ selector, treatment),
+ appId, null, selector, treatment);
this.one = checkNotNull(one);
this.two = checkNotNull(two);
}
+ private static HostId min(HostId one, HostId two) {
+ return one.hashCode() < two.hashCode() ? one : two;
+ }
+
+ private static HostId max(HostId one, HostId two) {
+ return one.hashCode() > two.hashCode() ? one : two;
+ }
+
/**
* Returns identifier of the first host.
*
@@ -56,31 +63,10 @@
}
@Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
- if (!super.equals(o)) {
- return false;
- }
-
- HostToHostIntent that = (HostToHostIntent) o;
- return Objects.equals(this.one, that.one)
- && Objects.equals(this.two, that.two);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(super.hashCode(), one, two);
- }
-
- @Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("id", id())
+ .add("appId", appId())
.add("selector", selector())
.add("treatment", treatment())
.add("one", one)
diff --git a/core/api/src/main/java/org/onlab/onos/net/intent/IdGenerator.java b/core/api/src/main/java/org/onlab/onos/net/intent/IdGenerator.java
deleted file mode 100644
index 0bba622..0000000
--- a/core/api/src/main/java/org/onlab/onos/net/intent/IdGenerator.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package org.onlab.onos.net.intent;
-//TODO is this the right package?
-
-/**
- * A generalized interface for ID generation
- *
- * {@link #getNewId()} generates a globally unique ID instance on
- * each invocation.
- *
- * @param <T> the type of ID
- */
-// TODO: do we need to define a base marker interface for ID,
-// then changed the type parameter to <T extends BaseId> something
-// like that?
-public interface IdGenerator<T> {
- /**
- * Returns a globally unique ID instance.
- *
- * @return globally unique ID instance
- */
- T getNewId();
-}
diff --git a/core/api/src/main/java/org/onlab/onos/net/intent/InstallableIntent.java b/core/api/src/main/java/org/onlab/onos/net/intent/InstallableIntent.java
deleted file mode 100644
index 488695c..0000000
--- a/core/api/src/main/java/org/onlab/onos/net/intent/InstallableIntent.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package org.onlab.onos.net.intent;
-
-import org.onlab.onos.net.Link;
-
-import java.util.Collection;
-
-/**
- * Abstraction of an intent that can be installed into
- * the underlying system without additional compilation.
- */
-public interface InstallableIntent extends Intent {
-
- /**
- * Returns the collection of links that are required for this installable
- * intent to exist.
- *
- * @return collection of links
- */
- // FIXME: replace this with 'NetworkResource'
- Collection<Link> requiredLinks();
-
-}
diff --git a/core/api/src/main/java/org/onlab/onos/net/intent/Intent.java b/core/api/src/main/java/org/onlab/onos/net/intent/Intent.java
index 3e339d1..f23a448 100644
--- a/core/api/src/main/java/org/onlab/onos/net/intent/Intent.java
+++ b/core/api/src/main/java/org/onlab/onos/net/intent/Intent.java
@@ -1,15 +1,109 @@
package org.onlab.onos.net.intent;
+import org.onlab.onos.ApplicationId;
+import org.onlab.onos.net.NetworkResource;
+
+import java.util.Collection;
+import java.util.Objects;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
/**
* Abstraction of an application level intent.
* <p/>
* Make sure that an Intent should be immutable when a new type is defined.
*/
-public interface Intent extends BatchOperationTarget {
+public abstract class Intent implements BatchOperationTarget {
+
+ private final IntentId id;
+ private final ApplicationId appId;
+ private final Collection<NetworkResource> resources;
+
+ /**
+ * Constructor for serializer.
+ */
+ protected Intent() {
+ this.id = null;
+ this.appId = null;
+ this.resources = null;
+ }
+
+ /**
+ * Creates a new intent.
+ *
+ * @param id intent identifier
+ * @param appId application identifier
+ * @param resources required network resources (optional)
+ */
+ protected Intent(IntentId id, ApplicationId appId,
+ Collection<NetworkResource> resources) {
+ this.appId = checkNotNull(appId, "Application ID cannot be null");
+ this.id = checkNotNull(id, "Fingerprint cannot be null");
+ this.resources = resources;
+ }
+
/**
* Returns the intent identifier.
*
+ * @return intent fingerprint
+ */
+ public IntentId id() {
+ return id;
+ }
+
+ /**
+ * Returns the identifier of the application that requested the intent.
+ *
+ * @return application identifier
+ */
+ public ApplicationId appId() {
+ return appId;
+ }
+
+ /**
+ * Returns the collection of resources required for this intent.
+ *
+ * @return collection of resources; may be null
+ */
+ public Collection<NetworkResource> resources() {
+ return resources;
+ }
+
+ /**
+ * Produces an intent identifier backed by hash-like fingerprint for the
+ * specified class of intent and its constituent fields.
+ *
+ * @param fields intent fields
* @return intent identifier
*/
- IntentId id();
+ protected static IntentId id(Object... fields) {
+ return IntentId.valueOf(Objects.hash(fields));
+ }
+
+ /**
+ * Indicates whether or not the intent is installable.
+ *
+ * @return true if installable
+ */
+ public boolean isInstallable() {
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(id);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null || getClass() != obj.getClass()) {
+ return false;
+ }
+ final Intent other = (Intent) obj;
+ return Objects.equals(this.id, other.id);
+ }
+
}
diff --git a/core/api/src/main/java/org/onlab/onos/net/intent/IntentExtensionService.java b/core/api/src/main/java/org/onlab/onos/net/intent/IntentExtensionService.java
index 8deb372..50e803c 100644
--- a/core/api/src/main/java/org/onlab/onos/net/intent/IntentExtensionService.java
+++ b/core/api/src/main/java/org/onlab/onos/net/intent/IntentExtensionService.java
@@ -38,7 +38,7 @@
* @param installer intent installer
* @param <T> the type of installable intent
*/
- <T extends InstallableIntent> void registerInstaller(Class<T> cls, IntentInstaller<T> installer);
+ <T extends Intent> void registerInstaller(Class<T> cls, IntentInstaller<T> installer);
/**
* Unregisters the installer for the given installable intent class.
@@ -46,12 +46,12 @@
* @param cls installable intent class
* @param <T> the type of installable intent
*/
- <T extends InstallableIntent> void unregisterInstaller(Class<T> cls);
+ <T extends Intent> void unregisterInstaller(Class<T> cls);
/**
* Returns immutable set of bindings of currently registered intent installers.
*
* @return the set of installer bindings
*/
- Map<Class<? extends InstallableIntent>, IntentInstaller<? extends InstallableIntent>> getInstallers();
+ Map<Class<? extends Intent>, IntentInstaller<? extends Intent>> getInstallers();
}
diff --git a/core/api/src/main/java/org/onlab/onos/net/intent/IntentId.java b/core/api/src/main/java/org/onlab/onos/net/intent/IntentId.java
index 8f132c0..08ab7fa 100644
--- a/core/api/src/main/java/org/onlab/onos/net/intent/IntentId.java
+++ b/core/api/src/main/java/org/onlab/onos/net/intent/IntentId.java
@@ -7,43 +7,37 @@
*/
public final class IntentId implements BatchOperationTarget {
- private static final int DEC = 10;
- private static final int HEX = 16;
-
- private final long id;
+ private final long fingerprint;
/**
* Creates an intent identifier from the specified string representation.
*
- * @param value long value
+ * @param fingerprint long value
* @return intent identifier
*/
- public static IntentId valueOf(String value) {
- long id = value.toLowerCase().startsWith("0x")
- ? Long.parseLong(value.substring(2), HEX)
- : Long.parseLong(value, DEC);
- return new IntentId(id);
+ public static IntentId valueOf(long fingerprint) {
+ return new IntentId(fingerprint);
}
/**
* Constructor for serializer.
*/
- protected IntentId() {
- this.id = 0;
+ IntentId() {
+ this.fingerprint = 0;
}
/**
* Constructs the ID corresponding to a given long value.
*
- * @param id the underlying value of this ID
+ * @param fingerprint the underlying value of this ID
*/
- public IntentId(long id) {
- this.id = id;
+ IntentId(long fingerprint) {
+ this.fingerprint = fingerprint;
}
@Override
public int hashCode() {
- return (int) (id ^ (id >>> 32));
+ return (int) (fingerprint ^ (fingerprint >>> 32));
}
@Override
@@ -51,18 +45,16 @@
if (obj == this) {
return true;
}
-
if (!(obj instanceof IntentId)) {
return false;
}
-
IntentId that = (IntentId) obj;
- return this.id == that.id;
+ return this.fingerprint == that.fingerprint;
}
@Override
public String toString() {
- return "0x" + Long.toHexString(id);
+ return "0x" + Long.toHexString(fingerprint);
}
}
diff --git a/core/api/src/main/java/org/onlab/onos/net/intent/IntentInstaller.java b/core/api/src/main/java/org/onlab/onos/net/intent/IntentInstaller.java
index 468017f..c403846 100644
--- a/core/api/src/main/java/org/onlab/onos/net/intent/IntentInstaller.java
+++ b/core/api/src/main/java/org/onlab/onos/net/intent/IntentInstaller.java
@@ -7,7 +7,7 @@
/**
* Abstraction of entity capable of installing intents to the environment.
*/
-public interface IntentInstaller<T extends InstallableIntent> {
+public interface IntentInstaller<T extends Intent> {
/**
* Installs the specified intent to the environment.
*
diff --git a/core/api/src/main/java/org/onlab/onos/net/intent/IntentStore.java b/core/api/src/main/java/org/onlab/onos/net/intent/IntentStore.java
index d693c9b..c234b0f 100644
--- a/core/api/src/main/java/org/onlab/onos/net/intent/IntentStore.java
+++ b/core/api/src/main/java/org/onlab/onos/net/intent/IntentStore.java
@@ -77,8 +77,7 @@
* @param intentId original intent identifier
* @param installableIntents compiled installable intents
*/
- void addInstallableIntents(IntentId intentId,
- List<InstallableIntent> installableIntents);
+ void addInstallableIntents(IntentId intentId, List<Intent> installableIntents);
/**
* Returns the list of the installable events associated with the specified
@@ -87,7 +86,7 @@
* @param intentId original intent identifier
* @return compiled installable intents
*/
- List<InstallableIntent> getInstallableIntents(IntentId intentId);
+ List<Intent> getInstallableIntents(IntentId intentId);
// TODO: this should be triggered from with the store as a result of removeIntent call
diff --git a/core/api/src/main/java/org/onlab/onos/net/intent/LinkCollectionIntent.java b/core/api/src/main/java/org/onlab/onos/net/intent/LinkCollectionIntent.java
index 6a8b002..4c193ee 100644
--- a/core/api/src/main/java/org/onlab/onos/net/intent/LinkCollectionIntent.java
+++ b/core/api/src/main/java/org/onlab/onos/net/intent/LinkCollectionIntent.java
@@ -1,21 +1,19 @@
package org.onlab.onos.net.intent;
-import java.util.Collection;
-import java.util.Objects;
-import java.util.Set;
-
+import com.google.common.base.MoreObjects;
+import org.onlab.onos.ApplicationId;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.Link;
import org.onlab.onos.net.flow.TrafficSelector;
import org.onlab.onos.net.flow.TrafficTreatment;
-import com.google.common.base.MoreObjects;
+import java.util.Set;
/**
* Abstraction of a connectivity intent that is implemented by a set of path
* segments.
*/
-public final class LinkCollectionIntent extends ConnectivityIntent implements InstallableIntent {
+public final class LinkCollectionIntent extends ConnectivityIntent {
private final Set<Link> links;
@@ -25,34 +23,33 @@
* Creates a new point-to-point intent with the supplied ingress/egress
* ports and using the specified explicit path.
*
- * @param id intent identifier
+ * @param appId application identifier
* @param selector traffic match
* @param treatment action
* @param links traversed links
* @param egressPoint egress point
* @throws NullPointerException {@code path} is null
*/
- public LinkCollectionIntent(IntentId id,
+ public LinkCollectionIntent(ApplicationId appId,
TrafficSelector selector,
TrafficTreatment treatment,
Set<Link> links,
ConnectPoint egressPoint) {
- super(id, selector, treatment);
+ super(id(LinkCollectionIntent.class, selector, treatment, links, egressPoint),
+ appId, resources(links), selector, treatment);
this.links = links;
this.egressPoint = egressPoint;
}
+ /**
+ * Constructor for serializer.
+ */
protected LinkCollectionIntent() {
super();
this.links = null;
this.egressPoint = null;
}
- @Override
- public Collection<Link> requiredLinks() {
- return links;
- }
-
/**
* Returns the set of links that represent the network connections needed
* by this intent.
@@ -73,34 +70,17 @@
}
@Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
- if (!super.equals(o)) {
- return false;
- }
-
- LinkCollectionIntent that = (LinkCollectionIntent) o;
-
- return Objects.equals(this.links, that.links) &&
- Objects.equals(this.egressPoint, that.egressPoint);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(super.hashCode(), links, egressPoint);
+ public boolean isInstallable() {
+ return true;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("id", id())
- .add("match", selector())
- .add("action", treatment())
+ .add("appId", appId())
+ .add("selector", selector())
+ .add("treatment", treatment())
.add("links", links())
.add("egress", egressPoint())
.toString();
diff --git a/core/api/src/main/java/org/onlab/onos/net/intent/MultiPointToSinglePointIntent.java b/core/api/src/main/java/org/onlab/onos/net/intent/MultiPointToSinglePointIntent.java
index 8ee4a9e..7c638aa 100644
--- a/core/api/src/main/java/org/onlab/onos/net/intent/MultiPointToSinglePointIntent.java
+++ b/core/api/src/main/java/org/onlab/onos/net/intent/MultiPointToSinglePointIntent.java
@@ -2,11 +2,11 @@
import com.google.common.base.MoreObjects;
import com.google.common.collect.Sets;
+import org.onlab.onos.ApplicationId;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.flow.TrafficSelector;
import org.onlab.onos.net.flow.TrafficTreatment;
-import java.util.Objects;
import java.util.Set;
import static com.google.common.base.Preconditions.checkArgument;
@@ -22,11 +22,11 @@
/**
* Creates a new multi-to-single point connectivity intent for the specified
- * traffic match and action.
+ * traffic selector and treatment.
*
- * @param id intent identifier
- * @param match traffic match
- * @param action action
+ * @param appId application identifier
+ * @param selector traffic selector
+ * @param treatment treatment
* @param ingressPoints set of ports from which ingress traffic originates
* @param egressPoint port to which traffic will egress
* @throws NullPointerException if {@code ingressPoints} or
@@ -34,15 +34,16 @@
* @throws IllegalArgumentException if the size of {@code ingressPoints} is
* not more than 1
*/
- public MultiPointToSinglePointIntent(IntentId id, TrafficSelector match,
- TrafficTreatment action,
+ public MultiPointToSinglePointIntent(ApplicationId appId,
+ TrafficSelector selector,
+ TrafficTreatment treatment,
Set<ConnectPoint> ingressPoints,
ConnectPoint egressPoint) {
- super(id, match, action);
+ super(id(MultiPointToSinglePointIntent.class, selector, treatment,
+ ingressPoints, egressPoint), appId, null, selector, treatment);
checkNotNull(ingressPoints);
- checkArgument(!ingressPoints.isEmpty(),
- "there should be at least one ingress port");
+ checkArgument(!ingressPoints.isEmpty(), "Ingress point set cannot be empty");
this.ingressPoints = Sets.newHashSet(ingressPoints);
this.egressPoint = checkNotNull(egressPoint);
@@ -77,35 +78,14 @@
}
@Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
- if (!super.equals(o)) {
- return false;
- }
-
- MultiPointToSinglePointIntent that = (MultiPointToSinglePointIntent) o;
- return Objects.equals(this.ingressPoints, that.ingressPoints)
- && Objects.equals(this.egressPoint, that.egressPoint);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(super.hashCode(), ingressPoints, egressPoint);
- }
-
- @Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("id", id())
- .add("match", selector())
- .add("action", treatment())
- .add("ingressPoints", ingressPoints())
- .add("egressPoint", egressPoint())
+ .add("appId", appId())
+ .add("selector", selector())
+ .add("treatment", treatment())
+ .add("ingress", ingressPoints())
+ .add("egress", egressPoint())
.toString();
}
}
diff --git a/core/api/src/main/java/org/onlab/onos/net/intent/OpticalConnectivityIntent.java b/core/api/src/main/java/org/onlab/onos/net/intent/OpticalConnectivityIntent.java
deleted file mode 100644
index b99eb70..0000000
--- a/core/api/src/main/java/org/onlab/onos/net/intent/OpticalConnectivityIntent.java
+++ /dev/null
@@ -1,58 +0,0 @@
-package org.onlab.onos.net.intent;
-
-import org.onlab.onos.net.ConnectPoint;
-
-// TODO: consider if this intent should be sub-class of ConnectivityIntent
-
-/**
- * An optical layer Intent for a connectivity from a transponder port to another
- * transponder port.
- * <p/>
- * This class doesn't accepts lambda specifier. This class computes path between
- * ports and assign lambda automatically. The lambda can be specified using
- * OpticalPathFlow class.
- */
-public class OpticalConnectivityIntent extends AbstractIntent {
- protected ConnectPoint src;
- protected ConnectPoint dst;
-
- /**
- * Constructor.
- *
- * @param id ID for this new Intent object.
- * @param src The source transponder port.
- * @param dst The destination transponder port.
- */
- public OpticalConnectivityIntent(IntentId id, ConnectPoint src, ConnectPoint dst) {
- super(id);
- this.src = src;
- this.dst = dst;
- }
-
- /**
- * Constructor for serializer.
- */
- protected OpticalConnectivityIntent() {
- super();
- this.src = null;
- this.dst = null;
- }
-
- /**
- * Gets source transponder port.
- *
- * @return The source transponder port.
- */
- public ConnectPoint getSrcConnectPoint() {
- return src;
- }
-
- /**
- * Gets destination transponder port.
- *
- * @return The source transponder port.
- */
- public ConnectPoint getDst() {
- return dst;
- }
-}
diff --git a/core/api/src/main/java/org/onlab/onos/net/intent/PacketConnectivityIntent.java b/core/api/src/main/java/org/onlab/onos/net/intent/PacketConnectivityIntent.java
deleted file mode 100644
index 893d70e..0000000
--- a/core/api/src/main/java/org/onlab/onos/net/intent/PacketConnectivityIntent.java
+++ /dev/null
@@ -1,177 +0,0 @@
-package org.onlab.onos.net.intent;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.onlab.onos.net.ConnectPoint;
-import org.onlab.onos.net.flow.TrafficSelector;
-
-// TODO: consider if this intent should be sub-class of Connectivity intent
-/**
- * A packet layer Intent for a connectivity from a set of ports to a set of
- * ports.
- * <p>
- * TODO: Design methods to support the ReactiveForwarding and the SDN-IP. <br>
- * NOTE: Should this class support modifier methods? Should this object a
- * read-only object?
- */
-public class PacketConnectivityIntent extends AbstractIntent {
- protected Set<ConnectPoint> srcConnectPoints;
- protected TrafficSelector selector;
- protected Set<ConnectPoint> dstConnectPoints;
- protected boolean canSetupOpticalFlow;
- protected int idleTimeoutValue;
- protected int hardTimeoutValue;
-
- /**
- * Creates a connectivity intent for the packet layer.
- * <p>
- * When the "canSetupOpticalFlow" option is true, this intent will compute
- * the packet/optical converged path, decompose it to the OpticalPathFlow
- * and the PacketPathFlow objects, and execute the operations to add them
- * considering the dependency between the packet and optical layers.
- *
- * @param id ID for this new Intent object.
- * @param srcConnectPoints The set of source switch ports.
- * @param match Traffic specifier for this object.
- * @param dstConnectPoints The set of destination switch ports.
- * @param canSetupOpticalFlow The flag whether this intent can create
- * optical flows if needed.
- */
- public PacketConnectivityIntent(IntentId id,
- Collection<ConnectPoint> srcConnectPoints, TrafficSelector match,
- Collection<ConnectPoint> dstConnectPoints, boolean canSetupOpticalFlow) {
- super(id);
- this.srcConnectPoints = new HashSet<ConnectPoint>(srcConnectPoints);
- this.selector = match;
- this.dstConnectPoints = new HashSet<ConnectPoint>(dstConnectPoints);
- this.canSetupOpticalFlow = canSetupOpticalFlow;
- this.idleTimeoutValue = 0;
- this.hardTimeoutValue = 0;
-
- // TODO: check consistency between these parameters.
- }
-
- /**
- * Constructor for serializer.
- */
- protected PacketConnectivityIntent() {
- super();
- this.srcConnectPoints = null;
- this.selector = null;
- this.dstConnectPoints = null;
- this.canSetupOpticalFlow = false;
- this.idleTimeoutValue = 0;
- this.hardTimeoutValue = 0;
- }
-
- /**
- * Gets the set of source switch ports.
- *
- * @return the set of source switch ports.
- */
- public Collection<ConnectPoint> getSrcConnectPoints() {
- return Collections.unmodifiableCollection(srcConnectPoints);
- }
-
- /**
- * Gets the traffic specifier.
- *
- * @return The traffic specifier.
- */
- public TrafficSelector getMatch() {
- return selector;
- }
-
- /**
- * Gets the set of destination switch ports.
- *
- * @return the set of destination switch ports.
- */
- public Collection<ConnectPoint> getDstConnectPoints() {
- return Collections.unmodifiableCollection(dstConnectPoints);
- }
-
- /**
- * Adds the specified port to the set of source ports.
- *
- * @param port ConnectPoint object to be added
- */
- public void addSrcConnectPoint(ConnectPoint port) {
- // TODO implement it.
- }
-
- /**
- * Adds the specified port to the set of destination ports.
- *
- * @param port ConnectPoint object to be added
- */
- public void addDstConnectPoint(ConnectPoint port) {
- // TODO implement it.
- }
-
- /**
- * Removes the specified port from the set of source ports.
- *
- * @param port ConnectPoint object to be removed
- */
- public void removeSrcConnectPoint(ConnectPoint port) {
- // TODO implement it.
- }
-
- /**
- * Removes the specified port from the set of destination ports.
- *
- * @param port ConnectPoint object to be removed
- */
- public void removeDstConnectPoint(ConnectPoint port) {
- // TODO implement it.
- }
-
- /**
- * Sets idle-timeout value.
- *
- * @param timeout Idle-timeout value (seconds)
- */
- public void setIdleTimeout(int timeout) {
- idleTimeoutValue = timeout;
- }
-
- /**
- * Sets hard-timeout value.
- *
- * @param timeout Hard-timeout value (seconds)
- */
- public void setHardTimeout(int timeout) {
- hardTimeoutValue = timeout;
- }
-
- /**
- * Gets idle-timeout value.
- *
- * @return Idle-timeout value (seconds)
- */
- public int getIdleTimeout() {
- return idleTimeoutValue;
- }
-
- /**
- * Gets hard-timeout value.
- *
- * @return Hard-timeout value (seconds)
- */
- public int getHardTimeout() {
- return hardTimeoutValue;
- }
-
- /**
- * Returns whether this intent can create optical flows if needed.
- *
- * @return whether this intent can create optical flows.
- */
- public boolean canSetupOpticalFlow() {
- return canSetupOpticalFlow;
- }
-}
diff --git a/core/api/src/main/java/org/onlab/onos/net/intent/PathIntent.java b/core/api/src/main/java/org/onlab/onos/net/intent/PathIntent.java
index ff2e917..1e41120 100644
--- a/core/api/src/main/java/org/onlab/onos/net/intent/PathIntent.java
+++ b/core/api/src/main/java/org/onlab/onos/net/intent/PathIntent.java
@@ -1,19 +1,15 @@
package org.onlab.onos.net.intent;
import com.google.common.base.MoreObjects;
-import org.onlab.onos.net.ConnectPoint;
-import org.onlab.onos.net.Link;
+import org.onlab.onos.ApplicationId;
import org.onlab.onos.net.Path;
import org.onlab.onos.net.flow.TrafficSelector;
import org.onlab.onos.net.flow.TrafficTreatment;
-import java.util.Collection;
-import java.util.Objects;
-
/**
* Abstraction of explicitly path specified connectivity intent.
*/
-public class PathIntent extends PointToPointIntent implements InstallableIntent {
+public class PathIntent extends ConnectivityIntent {
private final Path path;
@@ -21,21 +17,22 @@
* Creates a new point-to-point intent with the supplied ingress/egress
* ports and using the specified explicit path.
*
- * @param id intent identifier
- * @param match traffic match
- * @param action action
- * @param ingressPort ingress port
- * @param egressPort egress port
- * @param path traversed links
+ * @param appId application identifier
+ * @param selector traffic selector
+ * @param treatment treatment
+ * @param path traversed links
* @throws NullPointerException {@code path} is null
*/
- public PathIntent(IntentId id, TrafficSelector match, TrafficTreatment action,
- ConnectPoint ingressPort, ConnectPoint egressPort,
- Path path) {
- super(id, match, action, ingressPort, egressPort);
+ public PathIntent(ApplicationId appId, TrafficSelector selector,
+ TrafficTreatment treatment, Path path) {
+ super(id(PathIntent.class, selector, treatment, path), appId,
+ resources(path.links()), selector, treatment);
this.path = path;
}
+ /**
+ * Constructor for serializer.
+ */
protected PathIntent() {
super();
this.path = null;
@@ -51,46 +48,19 @@
}
@Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
- if (!super.equals(o)) {
- return false;
- }
-
- PathIntent that = (PathIntent) o;
-
- if (!path.equals(that.path)) {
- return false;
- }
-
+ public boolean isInstallable() {
return true;
}
@Override
- public int hashCode() {
- return Objects.hash(super.hashCode(), path);
- }
-
- @Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("id", id())
- .add("match", selector())
- .add("action", treatment())
- .add("ingressPort", ingressPoint())
- .add("egressPort", egressPoint())
+ .add("appId", appId())
+ .add("selector", selector())
+ .add("treatment", treatment())
.add("path", path)
.toString();
}
- @Override
- public Collection<Link> requiredLinks() {
- return path.links();
- }
-
}
diff --git a/core/api/src/main/java/org/onlab/onos/net/intent/PointToPointIntent.java b/core/api/src/main/java/org/onlab/onos/net/intent/PointToPointIntent.java
index 7b7c18a..d170c27 100644
--- a/core/api/src/main/java/org/onlab/onos/net/intent/PointToPointIntent.java
+++ b/core/api/src/main/java/org/onlab/onos/net/intent/PointToPointIntent.java
@@ -1,12 +1,11 @@
package org.onlab.onos.net.intent;
import com.google.common.base.MoreObjects;
+import org.onlab.onos.ApplicationId;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.flow.TrafficSelector;
import org.onlab.onos.net.flow.TrafficTreatment;
-import java.util.Objects;
-
import static com.google.common.base.Preconditions.checkNotNull;
/**
@@ -21,18 +20,19 @@
* Creates a new point-to-point intent with the supplied ingress/egress
* ports.
*
- * @param id intent identifier
+ * @param appId application identifier
* @param selector traffic selector
* @param treatment treatment
* @param ingressPoint ingress port
* @param egressPoint egress port
* @throws NullPointerException if {@code ingressPoint} or {@code egressPoints} is null.
*/
- public PointToPointIntent(IntentId id, TrafficSelector selector,
+ public PointToPointIntent(ApplicationId appId, TrafficSelector selector,
TrafficTreatment treatment,
ConnectPoint ingressPoint,
ConnectPoint egressPoint) {
- super(id, selector, treatment);
+ super(id(PointToPointIntent.class, selector, treatment, ingressPoint, egressPoint),
+ appId, null, selector, treatment);
this.ingressPoint = checkNotNull(ingressPoint);
this.egressPoint = checkNotNull(egressPoint);
}
@@ -66,35 +66,14 @@
}
@Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
- if (!super.equals(o)) {
- return false;
- }
-
- PointToPointIntent that = (PointToPointIntent) o;
- return Objects.equals(this.ingressPoint, that.ingressPoint)
- && Objects.equals(this.egressPoint, that.egressPoint);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(super.hashCode(), ingressPoint, egressPoint);
- }
-
- @Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("id", id())
- .add("match", selector())
- .add("action", treatment())
- .add("ingressPoint", ingressPoint)
- .add("egressPoints", egressPoint)
+ .add("appId", appId())
+ .add("selector", selector())
+ .add("treatment", treatment())
+ .add("ingress", ingressPoint)
+ .add("egress", egressPoint)
.toString();
}
diff --git a/core/api/src/main/java/org/onlab/onos/net/intent/SinglePointToMultiPointIntent.java b/core/api/src/main/java/org/onlab/onos/net/intent/SinglePointToMultiPointIntent.java
index 2a17bfe..62e36e7 100644
--- a/core/api/src/main/java/org/onlab/onos/net/intent/SinglePointToMultiPointIntent.java
+++ b/core/api/src/main/java/org/onlab/onos/net/intent/SinglePointToMultiPointIntent.java
@@ -2,11 +2,11 @@
import com.google.common.base.MoreObjects;
import com.google.common.collect.Sets;
+import org.onlab.onos.ApplicationId;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.flow.TrafficSelector;
import org.onlab.onos.net.flow.TrafficTreatment;
-import java.util.Objects;
import java.util.Set;
import static com.google.common.base.Preconditions.checkArgument;
@@ -23,7 +23,7 @@
/**
* Creates a new single-to-multi point connectivity intent.
*
- * @param id intent identifier
+ * @param appId application identifier
* @param selector traffic selector
* @param treatment treatment
* @param ingressPoint port on which traffic will ingress
@@ -33,16 +33,15 @@
* @throws IllegalArgumentException if the size of {@code egressPoints} is
* not more than 1
*/
- public SinglePointToMultiPointIntent(IntentId id, TrafficSelector selector,
+ public SinglePointToMultiPointIntent(ApplicationId appId,
+ TrafficSelector selector,
TrafficTreatment treatment,
ConnectPoint ingressPoint,
Set<ConnectPoint> egressPoints) {
- super(id, selector, treatment);
-
+ super(id(SinglePointToMultiPointIntent.class, selector, treatment,
+ ingressPoint, egressPoints), appId, null, selector, treatment);
checkNotNull(egressPoints);
- checkArgument(!egressPoints.isEmpty(),
- "there should be at least one egress port");
-
+ checkArgument(!egressPoints.isEmpty(), "Egress point set cannot be empty");
this.ingressPoint = checkNotNull(ingressPoint);
this.egressPoints = Sets.newHashSet(egressPoints);
}
@@ -75,35 +74,14 @@
}
@Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
- if (!super.equals(o)) {
- return false;
- }
-
- SinglePointToMultiPointIntent that = (SinglePointToMultiPointIntent) o;
- return Objects.equals(this.ingressPoint, that.ingressPoint)
- && Objects.equals(this.egressPoints, that.egressPoints);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(super.hashCode(), ingressPoint, egressPoints);
- }
-
- @Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("id", id())
- .add("match", selector())
- .add("action", treatment())
- .add("ingressPoint", ingressPoint)
- .add("egressPort", egressPoints)
+ .add("appId", appId())
+ .add("selector", selector())
+ .add("treatment", treatment())
+ .add("ingress", ingressPoint)
+ .add("egress", egressPoints)
.toString();
}
diff --git a/core/api/src/main/java/org/onlab/onos/net/resource/BandwidthResourceAllocation.java b/core/api/src/main/java/org/onlab/onos/net/resource/BandwidthResourceAllocation.java
new file mode 100644
index 0000000..b542533
--- /dev/null
+++ b/core/api/src/main/java/org/onlab/onos/net/resource/BandwidthResourceAllocation.java
@@ -0,0 +1,8 @@
+package org.onlab.onos.net.resource;
+
+/**
+ * Representation of allocated bandwidth resource.
+ */
+public interface BandwidthResourceAllocation extends BandwidthResourceRequest {
+
+}
diff --git a/core/api/src/main/java/org/onlab/onos/net/resource/BandwidthResourceRequest.java b/core/api/src/main/java/org/onlab/onos/net/resource/BandwidthResourceRequest.java
new file mode 100644
index 0000000..2ea24b8
--- /dev/null
+++ b/core/api/src/main/java/org/onlab/onos/net/resource/BandwidthResourceRequest.java
@@ -0,0 +1,13 @@
+package org.onlab.onos.net.resource;
+
+/**
+ * Representation of a request for bandwidth resource.
+ */
+public interface BandwidthResourceRequest {
+ /**
+ * Returns the bandwidth resource.
+ *
+ * @return the bandwidth resource
+ */
+ Bandwidth bandwidth();
+}
diff --git a/core/api/src/main/java/org/onlab/onos/net/resource/Lambda.java b/core/api/src/main/java/org/onlab/onos/net/resource/Lambda.java
index 86ea08e..73c9488 100644
--- a/core/api/src/main/java/org/onlab/onos/net/resource/Lambda.java
+++ b/core/api/src/main/java/org/onlab/onos/net/resource/Lambda.java
@@ -30,6 +30,7 @@
/**
* Returns lambda as an int value.
+ *
* @return lambda as an int value
*/
public int toInt() {
diff --git a/core/api/src/main/java/org/onlab/onos/net/resource/LambdaResourceAllocation.java b/core/api/src/main/java/org/onlab/onos/net/resource/LambdaResourceAllocation.java
new file mode 100644
index 0000000..1ed63b4
--- /dev/null
+++ b/core/api/src/main/java/org/onlab/onos/net/resource/LambdaResourceAllocation.java
@@ -0,0 +1,13 @@
+package org.onlab.onos.net.resource;
+
+/**
+ * Representation of allocated lambda resource.
+ */
+public interface LambdaResourceAllocation extends LambdaResourceRequest {
+ /**
+ * Returns the lambda resource.
+ *
+ * @return the lambda resource
+ */
+ Lambda lambda();
+}
diff --git a/core/api/src/main/java/org/onlab/onos/net/resource/LambdaResourceRequest.java b/core/api/src/main/java/org/onlab/onos/net/resource/LambdaResourceRequest.java
new file mode 100644
index 0000000..dfb3b81
--- /dev/null
+++ b/core/api/src/main/java/org/onlab/onos/net/resource/LambdaResourceRequest.java
@@ -0,0 +1,8 @@
+package org.onlab.onos.net.resource;
+
+/**
+ * Representation of a request for lambda resource.
+ */
+public interface LambdaResourceRequest {
+
+}
diff --git a/core/api/src/main/java/org/onlab/onos/net/resource/LinkResourceAllocations.java b/core/api/src/main/java/org/onlab/onos/net/resource/LinkResourceAllocations.java
new file mode 100644
index 0000000..a3d3e87
--- /dev/null
+++ b/core/api/src/main/java/org/onlab/onos/net/resource/LinkResourceAllocations.java
@@ -0,0 +1,16 @@
+package org.onlab.onos.net.resource;
+
+import org.onlab.onos.net.Link;
+
+/**
+ * Representation of allocated link resources.
+ */
+public interface LinkResourceAllocations extends LinkResourceRequest {
+ /**
+ * Returns allocated resource for the given link.
+ *
+ * @param link the target link
+ * @return allocated resource for the link
+ */
+ ResourceAllocation getResourceAllocation(Link link);
+}
diff --git a/core/api/src/main/java/org/onlab/onos/net/resource/LinkResourceRequest.java b/core/api/src/main/java/org/onlab/onos/net/resource/LinkResourceRequest.java
new file mode 100644
index 0000000..3f9bf79
--- /dev/null
+++ b/core/api/src/main/java/org/onlab/onos/net/resource/LinkResourceRequest.java
@@ -0,0 +1,34 @@
+package org.onlab.onos.net.resource;
+
+import java.util.Collection;
+import java.util.Set;
+
+import org.onlab.onos.net.Link;
+import org.onlab.onos.net.intent.IntentId;
+
+/**
+ * Representation of a request for link resource.
+ */
+public interface LinkResourceRequest extends ResourceRequest {
+
+ /**
+ * Returns the {@link IntentId} associated with the request.
+ *
+ * @return the {@link IntentId} associated with the request
+ */
+ IntentId intendId();
+
+ /**
+ * Returns the set of target links.
+ *
+ * @return the set of target links
+ */
+ Collection<Link> links();
+
+ /**
+ * Returns the set of resource requests.
+ *
+ * @return the set of resource requests
+ */
+ Set<ResourceRequest> resources();
+}
diff --git a/core/api/src/main/java/org/onlab/onos/net/resource/LinkResourceService.java b/core/api/src/main/java/org/onlab/onos/net/resource/LinkResourceService.java
index d2736b6..1ea5723 100644
--- a/core/api/src/main/java/org/onlab/onos/net/resource/LinkResourceService.java
+++ b/core/api/src/main/java/org/onlab/onos/net/resource/LinkResourceService.java
@@ -1,10 +1,7 @@
package org.onlab.onos.net.resource;
-import java.util.Map;
-
import org.onlab.onos.net.Link;
import org.onlab.onos.net.intent.IntentId;
-import org.onlab.onos.net.intent.PathIntent;
/**
* Service for providing link resource allocation.
@@ -12,49 +9,48 @@
public interface LinkResourceService {
/**
- * Allocates resources along the path.
- * <p>
- * Tries to allocate given resources on the links along the path specified
- * by the given intent.
+ * Requests resources.
*
- * @param res resources to be allocated
- * @param intent an intent to be used for specifying the path
+ * @param req resources to be allocated
+ * @return allocated resources
*/
- void allocateResource(LinkResources res, PathIntent intent);
+ LinkResourceAllocations requestResources(LinkResourceRequest req);
/**
- * Releases resources along the path.
+ * Releases resources.
*
- * @param intentId an ID for the intent for specifying the path
+ * @param allocations resources to be released
*/
- void releaseResource(IntentId intentId);
+ void releaseResources(LinkResourceAllocations allocations);
/**
- * Returns all allocated resources to each link.
+ * Returns all allocated resources.
*
- * @return allocated resources to each link with {@link IntentId}
+ * @return allocated resources
*/
- Map<Link, Map<IntentId, LinkResources>> allocatedResources();
+ Iterable<LinkResourceAllocations> getAllocations();
/**
* Returns all allocated resources to given link.
*
* @param link a target link
- * @return allocated resources to the target link with {@link IntentId}
+ * @return allocated resources
*/
- Map<IntentId, LinkResources> allocatedResources(Link link);
+ Iterable<LinkResourceAllocations> getAllocations(Link link);
/**
- * Returns available resources for each link.
+ * Returns all IDs of intents using the given link.
*
- * @return available resources for each link
+ * @param link a target link
+ * @return IDs of intents using the link
*/
- Map<Link, LinkResources> availableResources();
+ Iterable<IntentId> getIntents(Link link);
/**
* Returns available resources for given link.
+ *
* @param link a target link
* @return available resources for the target link
*/
- LinkResources availableResources(Link link);
+ ResourceRequest getAvailableResources(Link link);
}
diff --git a/core/api/src/main/java/org/onlab/onos/net/resource/ResourceAllocation.java b/core/api/src/main/java/org/onlab/onos/net/resource/ResourceAllocation.java
new file mode 100644
index 0000000..5cc1414
--- /dev/null
+++ b/core/api/src/main/java/org/onlab/onos/net/resource/ResourceAllocation.java
@@ -0,0 +1,8 @@
+package org.onlab.onos.net.resource;
+
+/**
+ * Abstraction of allocated resource.
+ */
+public interface ResourceAllocation extends ResourceRequest {
+
+}
diff --git a/core/api/src/main/java/org/onlab/onos/net/resource/ResourceId.java b/core/api/src/main/java/org/onlab/onos/net/resource/ResourceId.java
new file mode 100644
index 0000000..5c4c9fc
--- /dev/null
+++ b/core/api/src/main/java/org/onlab/onos/net/resource/ResourceId.java
@@ -0,0 +1,8 @@
+package org.onlab.onos.net.resource;
+
+/**
+ * Representation of ID for allocated resource.
+ */
+public interface ResourceId {
+
+}
diff --git a/core/api/src/main/java/org/onlab/onos/net/resource/ResourceRequest.java b/core/api/src/main/java/org/onlab/onos/net/resource/ResourceRequest.java
new file mode 100644
index 0000000..bc3d904
--- /dev/null
+++ b/core/api/src/main/java/org/onlab/onos/net/resource/ResourceRequest.java
@@ -0,0 +1,8 @@
+package org.onlab.onos.net.resource;
+
+/**
+ * Abstraction of resource request.
+ */
+public interface ResourceRequest {
+
+}
diff --git a/core/api/src/main/java/org/onlab/onos/net/resource/package-info.java b/core/api/src/main/java/org/onlab/onos/net/resource/package-info.java
new file mode 100644
index 0000000..4e07a28
--- /dev/null
+++ b/core/api/src/main/java/org/onlab/onos/net/resource/package-info.java
@@ -0,0 +1,4 @@
+/**
+ * Services for reserving network resources, e.g. bandwidth, lambdas.
+ */
+package org.onlab.onos.net.resource;
\ No newline at end of file
diff --git a/core/api/src/test/java/org/onlab/onos/net/intent/ConnectivityIntentTest.java b/core/api/src/test/java/org/onlab/onos/net/intent/ConnectivityIntentTest.java
index 10a0069..03b101a 100644
--- a/core/api/src/test/java/org/onlab/onos/net/intent/ConnectivityIntentTest.java
+++ b/core/api/src/test/java/org/onlab/onos/net/intent/ConnectivityIntentTest.java
@@ -2,6 +2,8 @@
import java.util.Set;
+import org.onlab.onos.ApplicationId;
+import org.onlab.onos.TestApplicationId;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.PortNumber;
@@ -15,6 +17,8 @@
*/
public abstract class ConnectivityIntentTest extends IntentTest {
+ public static final ApplicationId APPID = new TestApplicationId("foo");
+
public static final IntentId IID = new IntentId(123);
public static final TrafficSelector MATCH = DefaultTrafficSelector.builder().build();
public static final TrafficTreatment NOP = DefaultTrafficTreatment.builder().build();
diff --git a/core/api/src/test/java/org/onlab/onos/net/intent/FakeIntentManager.java b/core/api/src/test/java/org/onlab/onos/net/intent/FakeIntentManager.java
index 58c5a9c..4b3fd37 100644
--- a/core/api/src/test/java/org/onlab/onos/net/intent/FakeIntentManager.java
+++ b/core/api/src/test/java/org/onlab/onos/net/intent/FakeIntentManager.java
@@ -18,11 +18,11 @@
private final Map<IntentId, Intent> intents = new HashMap<>();
private final Map<IntentId, IntentState> intentStates = new HashMap<>();
- private final Map<IntentId, List<InstallableIntent>> installables = new HashMap<>();
+ private final Map<IntentId, List<Intent>> installables = new HashMap<>();
private final Set<IntentListener> listeners = new HashSet<>();
private final Map<Class<? extends Intent>, IntentCompiler<? extends Intent>> compilers = new HashMap<>();
- private final Map<Class<? extends InstallableIntent>, IntentInstaller<? extends InstallableIntent>> installers
+ private final Map<Class<? extends Intent>, IntentInstaller<? extends Intent>> installers
= new HashMap<>();
private final ExecutorService executor = Executors.newSingleThreadExecutor();
@@ -54,7 +54,7 @@
@Override
public void run() {
try {
- List<InstallableIntent> installable = getInstallable(intent.id());
+ List<Intent> installable = getInstallable(intent.id());
executeWithdrawingPhase(intent, installable);
} catch (IntentException e) {
exceptions.add(e);
@@ -73,7 +73,7 @@
return compiler;
}
- private <T extends InstallableIntent> IntentInstaller<T> getInstaller(T intent) {
+ private <T extends Intent> IntentInstaller<T> getInstaller(T intent) {
@SuppressWarnings("unchecked")
IntentInstaller<T> installer = (IntentInstaller<T>) installers.get(intent
.getClass());
@@ -87,9 +87,9 @@
setState(intent, IntentState.COMPILING);
try {
// For the fake, we compile using a single level pass
- List<InstallableIntent> installable = new ArrayList<>();
+ List<Intent> installable = new ArrayList<>();
for (Intent compiled : getCompiler(intent).compile(intent)) {
- installable.add((InstallableIntent) compiled);
+ installable.add((Intent) compiled);
}
executeInstallingPhase(intent, installable);
@@ -100,10 +100,10 @@
}
private void executeInstallingPhase(Intent intent,
- List<InstallableIntent> installable) {
+ List<Intent> installable) {
setState(intent, IntentState.INSTALLING);
try {
- for (InstallableIntent ii : installable) {
+ for (Intent ii : installable) {
registerSubclassInstallerIfNeeded(ii);
getInstaller(ii).install(ii);
}
@@ -118,10 +118,10 @@
}
private void executeWithdrawingPhase(Intent intent,
- List<InstallableIntent> installable) {
+ List<Intent> installable) {
setState(intent, IntentState.WITHDRAWING);
try {
- for (InstallableIntent ii : installable) {
+ for (Intent ii : installable) {
getInstaller(ii).uninstall(ii);
}
removeInstallable(intent.id());
@@ -139,7 +139,7 @@
intentStates.put(intent.id(), state);
}
- private void putInstallable(IntentId id, List<InstallableIntent> installable) {
+ private void putInstallable(IntentId id, List<Intent> installable) {
installables.put(id, installable);
}
@@ -147,8 +147,8 @@
installables.remove(id);
}
- private List<InstallableIntent> getInstallable(IntentId id) {
- List<InstallableIntent> installable = installables.get(id);
+ private List<Intent> getInstallable(IntentId id) {
+ List<Intent> installable = installables.get(id);
if (installable != null) {
return installable;
} else {
@@ -228,19 +228,19 @@
}
@Override
- public <T extends InstallableIntent> void registerInstaller(Class<T> cls,
+ public <T extends Intent> void registerInstaller(Class<T> cls,
IntentInstaller<T> installer) {
installers.put(cls, installer);
}
@Override
- public <T extends InstallableIntent> void unregisterInstaller(Class<T> cls) {
+ public <T extends Intent> void unregisterInstaller(Class<T> cls) {
installers.remove(cls);
}
@Override
- public Map<Class<? extends InstallableIntent>,
- IntentInstaller<? extends InstallableIntent>> getInstallers() {
+ public Map<Class<? extends Intent>,
+ IntentInstaller<? extends Intent>> getInstallers() {
return Collections.unmodifiableMap(installers);
}
@@ -261,13 +261,13 @@
}
}
- private void registerSubclassInstallerIfNeeded(InstallableIntent intent) {
+ private void registerSubclassInstallerIfNeeded(Intent intent) {
if (!installers.containsKey(intent.getClass())) {
Class<?> cls = intent.getClass();
while (cls != Object.class) {
- // As long as we're within the InstallableIntent class
+ // As long as we're within the Intent class
// descendants
- if (InstallableIntent.class.isAssignableFrom(cls)) {
+ if (Intent.class.isAssignableFrom(cls)) {
IntentInstaller<?> installer = installers.get(cls);
if (installer != null) {
installers.put(intent.getClass(), installer);
diff --git a/core/api/src/test/java/org/onlab/onos/net/intent/IntentIdGenerator.java b/core/api/src/test/java/org/onlab/onos/net/intent/IntentIdGenerator.java
deleted file mode 100644
index 0ca669b..0000000
--- a/core/api/src/test/java/org/onlab/onos/net/intent/IntentIdGenerator.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package org.onlab.onos.net.intent;
-
-/**
- * This interface is for generator of IntentId. It is defined only for
- * testing purpose to keep type safety on mock creation.
- *
- * <p>
- * {@link #getNewId()} generates a globally unique {@link IntentId} instance
- * on each invocation. Application developers should not generate IntentId
- * by themselves. Instead use an implementation of this interface.
- * </p>
- */
-public interface IntentIdGenerator extends IdGenerator<IntentId> {
-}
diff --git a/core/api/src/test/java/org/onlab/onos/net/intent/IntentIdTest.java b/core/api/src/test/java/org/onlab/onos/net/intent/IntentIdTest.java
index 2a0824c..471e397 100644
--- a/core/api/src/test/java/org/onlab/onos/net/intent/IntentIdTest.java
+++ b/core/api/src/test/java/org/onlab/onos/net/intent/IntentIdTest.java
@@ -44,14 +44,8 @@
@Test
public void valueOf() {
- IntentId id = new IntentId(12345);
- assertEquals("incorrect valueOf", id, IntentId.valueOf("12345"));
- }
-
- @Test
- public void valueOfHex() {
IntentId id = new IntentId(0xdeadbeefL);
- assertEquals("incorrect valueOf", id, IntentId.valueOf(id.toString()));
+ assertEquals("incorrect valueOf", id, IntentId.valueOf(0xdeadbeefL));
}
}
diff --git a/core/api/src/test/java/org/onlab/onos/net/intent/IntentTest.java b/core/api/src/test/java/org/onlab/onos/net/intent/IntentTest.java
index a6cedf9..084017b 100644
--- a/core/api/src/test/java/org/onlab/onos/net/intent/IntentTest.java
+++ b/core/api/src/test/java/org/onlab/onos/net/intent/IntentTest.java
@@ -1,14 +1,12 @@
package org.onlab.onos.net.intent;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import org.junit.Test;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
-import org.junit.Test;
+import static org.junit.Assert.*;
/**
* Base facilities to test various intent tests.
@@ -33,11 +31,7 @@
assertTrue("should be equal", one.equals(like));
assertEquals("incorrect hashCode", one.hashCode(), like.hashCode());
-
assertFalse("should not be equal", one.equals(another));
-
- assertFalse("should not be equal", one.equals(null));
- assertFalse("should not be equal", one.equals("foo"));
}
@Test
diff --git a/core/api/src/test/java/org/onlab/onos/net/intent/MultiPointToSinglePointIntentTest.java b/core/api/src/test/java/org/onlab/onos/net/intent/MultiPointToSinglePointIntentTest.java
index 66d294a..83bec15 100644
--- a/core/api/src/test/java/org/onlab/onos/net/intent/MultiPointToSinglePointIntentTest.java
+++ b/core/api/src/test/java/org/onlab/onos/net/intent/MultiPointToSinglePointIntentTest.java
@@ -12,7 +12,7 @@
@Test
public void basics() {
MultiPointToSinglePointIntent intent = createOne();
- assertEquals("incorrect id", IID, intent.id());
+ assertEquals("incorrect id", APPID, intent.appId());
assertEquals("incorrect match", MATCH, intent.selector());
assertEquals("incorrect ingress", PS1, intent.ingressPoints());
assertEquals("incorrect egress", P2, intent.egressPoint());
@@ -20,11 +20,11 @@
@Override
protected MultiPointToSinglePointIntent createOne() {
- return new MultiPointToSinglePointIntent(IID, MATCH, NOP, PS1, P2);
+ return new MultiPointToSinglePointIntent(APPID, MATCH, NOP, PS1, P2);
}
@Override
protected MultiPointToSinglePointIntent createAnother() {
- return new MultiPointToSinglePointIntent(IID, MATCH, NOP, PS2, P1);
+ return new MultiPointToSinglePointIntent(APPID, MATCH, NOP, PS2, P1);
}
}
diff --git a/core/api/src/test/java/org/onlab/onos/net/intent/PathIntentTest.java b/core/api/src/test/java/org/onlab/onos/net/intent/PathIntentTest.java
index 7c15c37..715c998 100644
--- a/core/api/src/test/java/org/onlab/onos/net/intent/PathIntentTest.java
+++ b/core/api/src/test/java/org/onlab/onos/net/intent/PathIntentTest.java
@@ -16,21 +16,19 @@
@Test
public void basics() {
PathIntent intent = createOne();
- assertEquals("incorrect id", IID, intent.id());
+ assertEquals("incorrect id", APPID, intent.appId());
assertEquals("incorrect match", MATCH, intent.selector());
assertEquals("incorrect action", NOP, intent.treatment());
- assertEquals("incorrect ingress", P1, intent.ingressPoint());
- assertEquals("incorrect egress", P2, intent.egressPoint());
assertEquals("incorrect path", PATH1, intent.path());
}
@Override
protected PathIntent createOne() {
- return new PathIntent(IID, MATCH, NOP, P1, P2, PATH1);
+ return new PathIntent(APPID, MATCH, NOP, PATH1);
}
@Override
protected PathIntent createAnother() {
- return new PathIntent(IID, MATCH, NOP, P1, P3, PATH2);
+ return new PathIntent(APPID, MATCH, NOP, PATH2);
}
}
diff --git a/core/api/src/test/java/org/onlab/onos/net/intent/PointToPointIntentTest.java b/core/api/src/test/java/org/onlab/onos/net/intent/PointToPointIntentTest.java
index e0c5562..9fbc255 100644
--- a/core/api/src/test/java/org/onlab/onos/net/intent/PointToPointIntentTest.java
+++ b/core/api/src/test/java/org/onlab/onos/net/intent/PointToPointIntentTest.java
@@ -12,7 +12,7 @@
@Test
public void basics() {
PointToPointIntent intent = createOne();
- assertEquals("incorrect id", IID, intent.id());
+ assertEquals("incorrect id", APPID, intent.appId());
assertEquals("incorrect match", MATCH, intent.selector());
assertEquals("incorrect ingress", P1, intent.ingressPoint());
assertEquals("incorrect egress", P2, intent.egressPoint());
@@ -20,11 +20,11 @@
@Override
protected PointToPointIntent createOne() {
- return new PointToPointIntent(IID, MATCH, NOP, P1, P2);
+ return new PointToPointIntent(APPID, MATCH, NOP, P1, P2);
}
@Override
protected PointToPointIntent createAnother() {
- return new PointToPointIntent(IID, MATCH, NOP, P2, P1);
+ return new PointToPointIntent(APPID, MATCH, NOP, P2, P1);
}
}
diff --git a/core/api/src/test/java/org/onlab/onos/net/intent/SinglePointToMultiPointIntentTest.java b/core/api/src/test/java/org/onlab/onos/net/intent/SinglePointToMultiPointIntentTest.java
index 64c9292..a1c68ee 100644
--- a/core/api/src/test/java/org/onlab/onos/net/intent/SinglePointToMultiPointIntentTest.java
+++ b/core/api/src/test/java/org/onlab/onos/net/intent/SinglePointToMultiPointIntentTest.java
@@ -12,7 +12,7 @@
@Test
public void basics() {
SinglePointToMultiPointIntent intent = createOne();
- assertEquals("incorrect id", IID, intent.id());
+ assertEquals("incorrect id", APPID, intent.appId());
assertEquals("incorrect match", MATCH, intent.selector());
assertEquals("incorrect ingress", P1, intent.ingressPoint());
assertEquals("incorrect egress", PS2, intent.egressPoints());
@@ -20,11 +20,11 @@
@Override
protected SinglePointToMultiPointIntent createOne() {
- return new SinglePointToMultiPointIntent(IID, MATCH, NOP, P1, PS2);
+ return new SinglePointToMultiPointIntent(APPID, MATCH, NOP, P1, PS2);
}
@Override
protected SinglePointToMultiPointIntent createAnother() {
- return new SinglePointToMultiPointIntent(IID, MATCH, NOP, P2, PS1);
+ return new SinglePointToMultiPointIntent(APPID, MATCH, NOP, P2, PS1);
}
}
diff --git a/core/api/src/test/java/org/onlab/onos/net/intent/TestInstallableIntent.java b/core/api/src/test/java/org/onlab/onos/net/intent/TestInstallableIntent.java
index 3265925..9476190 100644
--- a/core/api/src/test/java/org/onlab/onos/net/intent/TestInstallableIntent.java
+++ b/core/api/src/test/java/org/onlab/onos/net/intent/TestInstallableIntent.java
@@ -1,25 +1,18 @@
package org.onlab.onos.net.intent;
-//TODO is this the right package?
-import org.onlab.onos.net.Link;
-
-import java.util.Collection;
+import org.onlab.onos.TestApplicationId;
/**
* An installable intent used in the unit test.
- *
- * FIXME: we don't want to expose this class publicly, but the current Kryo
- * serialization mechanism does not allow this class to be private and placed
- * on testing directory.
*/
-public class TestInstallableIntent extends AbstractIntent implements InstallableIntent {
+public class TestInstallableIntent extends Intent {
/**
* Constructs an instance with the specified intent ID.
*
* @param id intent ID
*/
public TestInstallableIntent(IntentId id) {
- super(id);
+ super(id, new TestApplicationId("foo"), null);
}
/**
@@ -30,7 +23,8 @@
}
@Override
- public Collection<Link> requiredLinks() {
- return null;
+ public boolean isInstallable() {
+ return true;
}
+
}
diff --git a/core/api/src/test/java/org/onlab/onos/net/intent/TestIntent.java b/core/api/src/test/java/org/onlab/onos/net/intent/TestIntent.java
index 2f30727..a9d1656 100644
--- a/core/api/src/test/java/org/onlab/onos/net/intent/TestIntent.java
+++ b/core/api/src/test/java/org/onlab/onos/net/intent/TestIntent.java
@@ -1,21 +1,18 @@
package org.onlab.onos.net.intent;
-//TODO is this the right package?
+
+import org.onlab.onos.TestApplicationId;
/**
* An intent used in the unit test.
- *
- * FIXME: we don't want to expose this class publicly, but the current Kryo
- * serialization mechanism does not allow this class to be private and placed
- * on testing directory.
*/
-public class TestIntent extends AbstractIntent {
+public class TestIntent extends Intent {
/**
* Constructs an instance with the specified intent ID.
*
* @param id intent ID
*/
public TestIntent(IntentId id) {
- super(id);
+ super(id, new TestApplicationId("foo"), null);
}
/**
diff --git a/core/api/src/test/java/org/onlab/onos/net/intent/TestSubclassInstallableIntent.java b/core/api/src/test/java/org/onlab/onos/net/intent/TestSubclassInstallableIntent.java
index 40765c2..bfeb985 100644
--- a/core/api/src/test/java/org/onlab/onos/net/intent/TestSubclassInstallableIntent.java
+++ b/core/api/src/test/java/org/onlab/onos/net/intent/TestSubclassInstallableIntent.java
@@ -1,14 +1,9 @@
package org.onlab.onos.net.intent;
-//TODO is this the right package?
/**
* An intent used in the unit test.
- *
- * FIXME: we don't want to expose this class publicly, but the current Kryo
- * serialization mechanism does not allow this class to be private and placed
- * on testing directory.
*/
-public class TestSubclassInstallableIntent extends TestInstallableIntent implements InstallableIntent {
+public class TestSubclassInstallableIntent extends TestInstallableIntent {
/**
* Constructs an instance with the specified intent ID.
*
diff --git a/core/api/src/test/java/org/onlab/onos/net/intent/TestSubclassIntent.java b/core/api/src/test/java/org/onlab/onos/net/intent/TestSubclassIntent.java
index 43bb0dd..c8d6996 100644
--- a/core/api/src/test/java/org/onlab/onos/net/intent/TestSubclassIntent.java
+++ b/core/api/src/test/java/org/onlab/onos/net/intent/TestSubclassIntent.java
@@ -1,12 +1,7 @@
package org.onlab.onos.net.intent;
-//TODO is this the right package?
/**
* An intent used in the unit test.
- *
- * FIXME: we don't want to expose this class publicly, but the current Kryo
- * serialization mechanism does not allow this class to be private and placed
- * on testing directory.
*/
public class TestSubclassIntent extends TestIntent {
/**
diff --git a/core/net/src/main/java/org/onlab/onos/impl/CoreManager.java b/core/net/src/main/java/org/onlab/onos/impl/CoreManager.java
index edfc080..da1f8c9 100644
--- a/core/net/src/main/java/org/onlab/onos/impl/CoreManager.java
+++ b/core/net/src/main/java/org/onlab/onos/impl/CoreManager.java
@@ -27,6 +27,7 @@
private static Version version = Version.version("1.0.0-SNAPSHOT");
private final Map<Short, DefaultApplicationId> appIds = new ConcurrentHashMap<>();
+ private final Map<String, DefaultApplicationId> appIdsByName = new ConcurrentHashMap<>();
// TODO: work in progress
@@ -50,9 +51,13 @@
@Override
public ApplicationId registerApplication(String name) {
- short id = (short) ID_DISPENSER.getAndIncrement();
- DefaultApplicationId appId = new DefaultApplicationId(id, name);
- appIds.put(id, appId);
+ DefaultApplicationId appId = appIdsByName.get(name);
+ if (appId == null) {
+ short id = (short) ID_DISPENSER.getAndIncrement();
+ appId = new DefaultApplicationId(id, name);
+ appIds.put(id, appId);
+ appIdsByName.put(name, appId);
+ }
return appId;
}
diff --git a/core/net/src/main/java/org/onlab/onos/net/flow/impl/FlowRuleManager.java b/core/net/src/main/java/org/onlab/onos/net/flow/impl/FlowRuleManager.java
index 9ea99c3..525946e 100644
--- a/core/net/src/main/java/org/onlab/onos/net/flow/impl/FlowRuleManager.java
+++ b/core/net/src/main/java/org/onlab/onos/net/flow/impl/FlowRuleManager.java
@@ -104,24 +104,52 @@
public void applyFlowRules(FlowRule... flowRules) {
for (int i = 0; i < flowRules.length; i++) {
FlowRule f = flowRules[i];
- final Device device = deviceService.getDevice(f.deviceId());
- final FlowRuleProvider frp = getProvider(device.providerId());
- store.storeFlowRule(f);
- frp.applyFlowRule(f);
+ boolean local = store.storeFlowRule(f);
+ if (local) {
+ // TODO: aggregate all local rules and push down once?
+ applyFlowRulesToProviders(f);
+ }
+ }
+ }
+
+ private void applyFlowRulesToProviders(FlowRule... flowRules) {
+ DeviceId did = null;
+ FlowRuleProvider frp = null;
+ for (FlowRule f : flowRules) {
+ if (!f.deviceId().equals(did)) {
+ did = f.deviceId();
+ final Device device = deviceService.getDevice(did);
+ frp = getProvider(device.providerId());
+ }
+ if (frp != null) {
+ frp.applyFlowRule(f);
+ }
}
}
@Override
public void removeFlowRules(FlowRule... flowRules) {
FlowRule f;
- FlowRuleProvider frp;
- Device device;
for (int i = 0; i < flowRules.length; i++) {
f = flowRules[i];
- device = deviceService.getDevice(f.deviceId());
- store.deleteFlowRule(f);
- if (device != null) {
+ boolean local = store.deleteFlowRule(f);
+ if (local) {
+ // TODO: aggregate all local rules and push down once?
+ removeFlowRulesFromProviders(f);
+ }
+ }
+ }
+
+ private void removeFlowRulesFromProviders(FlowRule... flowRules) {
+ DeviceId did = null;
+ FlowRuleProvider frp = null;
+ for (FlowRule f : flowRules) {
+ if (!f.deviceId().equals(did)) {
+ did = f.deviceId();
+ final Device device = deviceService.getDevice(did);
frp = getProvider(device.providerId());
+ }
+ if (frp != null) {
frp.removeFlowRule(f);
}
}
@@ -135,8 +163,11 @@
for (FlowRule f : rules) {
store.deleteFlowRule(f);
+ // FIXME: only accept request and push to provider on internal event
device = deviceService.getDevice(f.deviceId());
frp = getProvider(device.providerId());
+ // FIXME: flows removed from store and flows removed from might diverge
+ // get rid of #removeRulesById?
frp.removeRulesById(id, f);
}
}
@@ -352,7 +383,23 @@
private class InternalStoreDelegate implements FlowRuleStoreDelegate {
@Override
public void notify(FlowRuleEvent event) {
- eventDispatcher.post(event);
+ switch (event.type()) {
+ case RULE_ADD_REQUESTED:
+ applyFlowRulesToProviders(event.subject());
+ break;
+ case RULE_REMOVE_REQUESTED:
+ removeFlowRulesFromProviders(event.subject());
+ break;
+
+ case RULE_ADDED:
+ case RULE_REMOVED:
+ case RULE_UPDATED:
+ // only dispatch events related to switch
+ eventDispatcher.post(event);
+ break;
+ default:
+ break;
+ }
}
}
diff --git a/core/net/src/main/java/org/onlab/onos/net/intent/impl/AbstractBlockAllocatorBasedIdGenerator.java b/core/net/src/main/java/org/onlab/onos/net/intent/impl/AbstractBlockAllocatorBasedIdGenerator.java
deleted file mode 100644
index 00b64da..0000000
--- a/core/net/src/main/java/org/onlab/onos/net/intent/impl/AbstractBlockAllocatorBasedIdGenerator.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package org.onlab.onos.net.intent.impl;
-
-import org.onlab.onos.net.intent.IdGenerator;
-
-/**
- * Base class of {@link IdGenerator} implementations which use {@link IdBlockAllocator} as
- * backend.
- *
- * @param <T> the type of ID
- */
-public abstract class AbstractBlockAllocatorBasedIdGenerator<T> implements IdGenerator<T> {
- protected final IdBlockAllocator allocator;
- protected IdBlock idBlock;
-
- /**
- * Constructs an ID generator which use {@link IdBlockAllocator} as backend.
- *
- * @param allocator
- */
- protected AbstractBlockAllocatorBasedIdGenerator(IdBlockAllocator allocator) {
- this.allocator = allocator;
- this.idBlock = allocator.allocateUniqueIdBlock();
- }
-
- @Override
- public synchronized T getNewId() {
- try {
- return convertFrom(idBlock.getNextId());
- } catch (UnavailableIdException e) {
- idBlock = allocator.allocateUniqueIdBlock();
- return convertFrom(idBlock.getNextId());
- }
- }
-
- /**
- * Returns an ID instance of {@code T} type from the long value.
- *
- * @param value original long value
- * @return ID instance
- */
- protected abstract T convertFrom(long value);
-}
diff --git a/core/net/src/main/java/org/onlab/onos/net/intent/impl/DummyIdBlockAllocator.java b/core/net/src/main/java/org/onlab/onos/net/intent/impl/DummyIdBlockAllocator.java
deleted file mode 100644
index f331aa2..0000000
--- a/core/net/src/main/java/org/onlab/onos/net/intent/impl/DummyIdBlockAllocator.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package org.onlab.onos.net.intent.impl;
-
-public class DummyIdBlockAllocator implements IdBlockAllocator {
- private long blockTop;
- private static final long BLOCK_SIZE = 0x1000000L;
-
- /**
- * Returns a block of IDs which are unique and unused.
- * Range of IDs is fixed size and is assigned incrementally as this method
- * called.
- *
- * @return an IdBlock containing a set of unique IDs
- */
- @Override
- public IdBlock allocateUniqueIdBlock() {
- synchronized (this) {
- long blockHead = blockTop;
- long blockTail = blockTop + BLOCK_SIZE;
-
- IdBlock block = new IdBlock(blockHead, BLOCK_SIZE);
- blockTop = blockTail;
-
- return block;
- }
- }
-
- @Override
- public IdBlock allocateUniqueIdBlock(long range) {
- throw new UnsupportedOperationException("Not supported yet");
- }
-}
diff --git a/core/net/src/main/java/org/onlab/onos/net/intent/impl/HostToHostIntentCompiler.java b/core/net/src/main/java/org/onlab/onos/net/intent/impl/HostToHostIntentCompiler.java
index 50faf38..e769982 100644
--- a/core/net/src/main/java/org/onlab/onos/net/intent/impl/HostToHostIntentCompiler.java
+++ b/core/net/src/main/java/org/onlab/onos/net/intent/impl/HostToHostIntentCompiler.java
@@ -11,11 +11,9 @@
import org.onlab.onos.net.flow.TrafficSelector;
import org.onlab.onos.net.host.HostService;
import org.onlab.onos.net.intent.HostToHostIntent;
-import org.onlab.onos.net.intent.IdGenerator;
import org.onlab.onos.net.intent.Intent;
import org.onlab.onos.net.intent.IntentCompiler;
import org.onlab.onos.net.intent.IntentExtensionService;
-import org.onlab.onos.net.intent.IntentId;
import org.onlab.onos.net.intent.PathIntent;
import org.onlab.onos.net.topology.PathService;
@@ -41,12 +39,8 @@
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected HostService hostService;
- protected IdGenerator<IntentId> intentIdGenerator;
-
@Activate
public void activate() {
- IdBlockAllocator idBlockAllocator = new DummyIdBlockAllocator();
- intentIdGenerator = new IdBlockAllocatorBasedIntentIdGenerator(idBlockAllocator);
intentManager.registerCompiler(HostToHostIntent.class, this);
}
@@ -70,13 +64,10 @@
// Creates a path intent from the specified path and original connectivity intent.
private Intent createPathIntent(Path path, Host src, Host dst,
HostToHostIntent intent) {
-
TrafficSelector selector = builder(intent.selector())
.matchEthSrc(src.mac()).matchEthDst(dst.mac()).build();
-
- return new PathIntent(intentIdGenerator.getNewId(),
- selector, intent.treatment(),
- path.src(), path.dst(), path);
+ return new PathIntent(intent.appId(), selector, intent.treatment(),
+ path);
}
private Path getPath(HostId one, HostId two) {
diff --git a/core/net/src/main/java/org/onlab/onos/net/intent/impl/IdBlock.java b/core/net/src/main/java/org/onlab/onos/net/intent/impl/IdBlock.java
deleted file mode 100644
index ce418ea..0000000
--- a/core/net/src/main/java/org/onlab/onos/net/intent/impl/IdBlock.java
+++ /dev/null
@@ -1,111 +0,0 @@
-package org.onlab.onos.net.intent.impl;
-
-import static com.google.common.base.Preconditions.checkArgument;
-
-import java.util.Objects;
-import java.util.concurrent.atomic.AtomicLong;
-
-import com.google.common.base.MoreObjects;
-
-/**
- * A class representing an ID space.
- */
-public final class IdBlock {
- private final long start;
- private final long size;
-
- private final AtomicLong currentId;
-
- /**
- * Constructs a new ID block with the specified size and initial value.
- *
- * @param start initial value of the block
- * @param size size of the block
- * @throws IllegalArgumentException if the size is less than or equal to 0
- */
- public IdBlock(long start, long size) {
- checkArgument(size > 0, "size should be more than 0, but %s", size);
-
- this.start = start;
- this.size = size;
-
- this.currentId = new AtomicLong(start);
- }
-
- // TODO: consider if this method is needed or not
- /**
- * Returns the initial value.
- *
- * @return initial value
- */
- public long getStart() {
- return start;
- }
-
- // TODO: consider if this method is needed or not
- /**
- * Returns the last value.
- *
- * @return last value
- */
- public long getEnd() {
- return start + size - 1;
- }
-
- /**
- * Returns the block size.
- *
- * @return block size
- */
- public long getSize() {
- return size;
- }
-
- /**
- * Returns the next ID in the block.
- *
- * @return next ID
- * @throws UnavailableIdException if there is no available ID in the block.
- */
- public long getNextId() {
- final long id = currentId.getAndIncrement();
- if (id > getEnd()) {
- throw new UnavailableIdException(String.format(
- "used all IDs in allocated space (size: %d, end: %d, current: %d)",
- size, getEnd(), id
- ));
- }
-
- return id;
- }
-
- // TODO: Do we really need equals and hashCode? Should it contain currentId?
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
-
- IdBlock that = (IdBlock) o;
- return Objects.equals(this.start, that.start)
- && Objects.equals(this.size, that.size)
- && Objects.equals(this.currentId.get(), that.currentId.get());
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(start, size, currentId);
- }
-
- @Override
- public String toString() {
- return MoreObjects.toStringHelper(getClass())
- .add("start", start)
- .add("size", size)
- .add("currentId", currentId)
- .toString();
- }
-}
diff --git a/core/net/src/main/java/org/onlab/onos/net/intent/impl/IdBlockAllocator.java b/core/net/src/main/java/org/onlab/onos/net/intent/impl/IdBlockAllocator.java
deleted file mode 100644
index 1adac02..0000000
--- a/core/net/src/main/java/org/onlab/onos/net/intent/impl/IdBlockAllocator.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package org.onlab.onos.net.intent.impl;
-
-/**
- * An interface that gives unique ID spaces.
- */
-public interface IdBlockAllocator {
- /**
- * Allocates a unique Id Block.
- *
- * @return Id Block.
- */
- IdBlock allocateUniqueIdBlock();
-
- /**
- * Allocates next unique id and retrieve a new range of ids if needed.
- *
- * @param range range to use for the identifier
- * @return Id Block.
- */
- IdBlock allocateUniqueIdBlock(long range);
-}
diff --git a/core/net/src/main/java/org/onlab/onos/net/intent/impl/IdBlockAllocatorBasedIntentIdGenerator.java b/core/net/src/main/java/org/onlab/onos/net/intent/impl/IdBlockAllocatorBasedIntentIdGenerator.java
deleted file mode 100644
index 9620e59..0000000
--- a/core/net/src/main/java/org/onlab/onos/net/intent/impl/IdBlockAllocatorBasedIntentIdGenerator.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package org.onlab.onos.net.intent.impl;
-
-import org.onlab.onos.net.intent.IntentId;
-
-/**
- * An implementation of {@link org.onlab.onos.net.intent.IdGenerator} of intent ID,
- * which uses {@link IdBlockAllocator}.
- */
-public class IdBlockAllocatorBasedIntentIdGenerator extends AbstractBlockAllocatorBasedIdGenerator<IntentId> {
-
- /**
- * Constructs an intent ID generator, which uses the specified ID block allocator
- * to generate a global unique intent ID.
- *
- * @param allocator the ID block allocator to use for generating intent IDs
- */
- public IdBlockAllocatorBasedIntentIdGenerator(IdBlockAllocator allocator) {
- super(allocator);
- }
-
- @Override
- protected IntentId convertFrom(long value) {
- return new IntentId(value);
- }
-}
diff --git a/core/net/src/main/java/org/onlab/onos/net/intent/impl/IntentManager.java b/core/net/src/main/java/org/onlab/onos/net/intent/impl/IntentManager.java
index ff1e948..03d5ce8 100644
--- a/core/net/src/main/java/org/onlab/onos/net/intent/impl/IntentManager.java
+++ b/core/net/src/main/java/org/onlab/onos/net/intent/impl/IntentManager.java
@@ -1,30 +1,8 @@
package org.onlab.onos.net.intent.impl;
-import static com.google.common.base.Preconditions.checkNotNull;
-import static java.util.concurrent.Executors.newSingleThreadExecutor;
-import static org.onlab.onos.net.intent.IntentState.COMPILING;
-import static org.onlab.onos.net.intent.IntentState.FAILED;
-import static org.onlab.onos.net.intent.IntentState.INSTALLED;
-import static org.onlab.onos.net.intent.IntentState.INSTALLING;
-import static org.onlab.onos.net.intent.IntentState.RECOMPILING;
-import static org.onlab.onos.net.intent.IntentState.WITHDRAWING;
-import static org.onlab.onos.net.intent.IntentState.WITHDRAWN;
-import static org.onlab.util.Tools.namedThreads;
-import static org.slf4j.LoggerFactory.getLogger;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
@@ -36,7 +14,6 @@
import org.onlab.onos.net.flow.CompletedBatchOperation;
import org.onlab.onos.net.flow.FlowRuleBatchOperation;
import org.onlab.onos.net.flow.FlowRuleService;
-import org.onlab.onos.net.intent.InstallableIntent;
import org.onlab.onos.net.intent.Intent;
import org.onlab.onos.net.intent.IntentCompiler;
import org.onlab.onos.net.intent.IntentEvent;
@@ -52,9 +29,24 @@
import org.onlab.onos.net.intent.IntentStoreDelegate;
import org.slf4j.Logger;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Lists;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static java.util.concurrent.Executors.newSingleThreadExecutor;
+import static org.onlab.onos.net.intent.IntentState.*;
+import static org.onlab.util.Tools.namedThreads;
+import static org.slf4j.LoggerFactory.getLogger;
/**
* An implementation of Intent Manager.
@@ -71,8 +63,8 @@
// Collections for compiler, installer, and listener are ONOS instance local
private final ConcurrentMap<Class<? extends Intent>,
IntentCompiler<? extends Intent>> compilers = new ConcurrentHashMap<>();
- private final ConcurrentMap<Class<? extends InstallableIntent>,
- IntentInstaller<? extends InstallableIntent>> installers = new ConcurrentHashMap<>();
+ private final ConcurrentMap<Class<? extends Intent>,
+ IntentInstaller<? extends Intent>> installers = new ConcurrentHashMap<>();
private final AbstractListenerRegistry<IntentEvent, IntentListener>
listenerRegistry = new AbstractListenerRegistry<>();
@@ -186,17 +178,17 @@
}
@Override
- public <T extends InstallableIntent> void registerInstaller(Class<T> cls, IntentInstaller<T> installer) {
+ public <T extends Intent> void registerInstaller(Class<T> cls, IntentInstaller<T> installer) {
installers.put(cls, installer);
}
@Override
- public <T extends InstallableIntent> void unregisterInstaller(Class<T> cls) {
+ public <T extends Intent> void unregisterInstaller(Class<T> cls) {
installers.remove(cls);
}
@Override
- public Map<Class<? extends InstallableIntent>, IntentInstaller<? extends InstallableIntent>> getInstallers() {
+ public Map<Class<? extends Intent>, IntentInstaller<? extends Intent>> getInstallers() {
return ImmutableMap.copyOf(installers);
}
@@ -223,7 +215,7 @@
* @param <T> the type of installable intent
* @return intent installer corresponding to the specified installable intent
*/
- private <T extends InstallableIntent> IntentInstaller<T> getInstaller(T intent) {
+ private <T extends Intent> IntentInstaller<T> getInstaller(T intent) {
@SuppressWarnings("unchecked")
IntentInstaller<T> installer = (IntentInstaller<T>) installers.get(intent.getClass());
if (installer == null) {
@@ -243,7 +235,7 @@
try {
// Compile the intent into installable derivatives.
- List<InstallableIntent> installable = compileIntent(intent);
+ List<Intent> installable = compileIntent(intent);
// If all went well, associate the resulting list of installable
// intents with the top-level intent and proceed to install.
@@ -264,12 +256,12 @@
* @param intent intent
* @return result of compilation
*/
- private List<InstallableIntent> compileIntent(Intent intent) {
- if (intent instanceof InstallableIntent) {
- return ImmutableList.of((InstallableIntent) intent);
+ private List<Intent> compileIntent(Intent intent) {
+ if (intent.isInstallable()) {
+ return ImmutableList.of(intent);
}
- List<InstallableIntent> installable = new ArrayList<>();
+ List<Intent> installable = new ArrayList<>();
// TODO do we need to registerSubclassCompiler?
for (Intent compiled : getCompiler(intent).compile(intent)) {
installable.addAll(compileIntent(compiled));
@@ -290,12 +282,12 @@
List<FlowRuleBatchOperation> installWork = Lists.newArrayList();
try {
- List<InstallableIntent> installables = store.getInstallableIntents(intent.id());
+ List<Intent> installables = store.getInstallableIntents(intent.id());
if (installables != null) {
- for (InstallableIntent installable : installables) {
+ for (Intent installable : installables) {
registerSubclassInstallerIfNeeded(installable);
trackerService.addTrackedResources(intent.id(),
- installable.requiredLinks());
+ installable.resources());
List<FlowRuleBatchOperation> batch = getInstaller(installable).install(installable);
installWork.addAll(batch);
}
@@ -324,14 +316,13 @@
try {
// Compile the intent into installable derivatives.
- List<InstallableIntent> installable = compileIntent(intent);
+ List<Intent> installable = compileIntent(intent);
// If all went well, compare the existing list of installable
// intents with the newly compiled list. If they are the same,
// bail, out since the previous approach was determined not to
// be viable.
- List<InstallableIntent> originalInstallable =
- store.getInstallableIntents(intent.id());
+ List<Intent> originalInstallable = store.getInstallableIntents(intent.id());
if (Objects.equals(originalInstallable, installable)) {
eventDispatcher.post(store.setState(intent, FAILED));
@@ -376,9 +367,9 @@
private void uninstallIntent(Intent intent, IntentState nextState) {
List<FlowRuleBatchOperation> uninstallWork = Lists.newArrayList();
try {
- List<InstallableIntent> installables = store.getInstallableIntents(intent.id());
+ List<Intent> installables = store.getInstallableIntents(intent.id());
if (installables != null) {
- for (InstallableIntent installable : installables) {
+ for (Intent installable : installables) {
List<FlowRuleBatchOperation> batches = getInstaller(installable).uninstall(installable);
uninstallWork.addAll(batches);
}
@@ -422,12 +413,12 @@
*
* @param intent intent
*/
- private void registerSubclassInstallerIfNeeded(InstallableIntent intent) {
+ private void registerSubclassInstallerIfNeeded(Intent intent) {
if (!installers.containsKey(intent.getClass())) {
Class<?> cls = intent.getClass();
while (cls != Object.class) {
- // As long as we're within the InstallableIntent class descendants
- if (InstallableIntent.class.isAssignableFrom(cls)) {
+ // As long as we're within the Intent class descendants
+ if (Intent.class.isAssignableFrom(cls)) {
IntentInstaller<?> installer = installers.get(cls);
if (installer != null) {
installers.put(intent.getClass(), installer);
@@ -505,8 +496,8 @@
private final IntentState nextState;
public IntentInstallMonitor(Intent intent,
- List<FlowRuleBatchOperation> work,
- IntentState nextState) {
+ List<FlowRuleBatchOperation> work,
+ IntentState nextState) {
this.intent = intent;
this.work = work;
// TODO how many Futures can be outstanding? one?
@@ -531,9 +522,7 @@
}
/**
- * Apply a list of FlowRules.
- *
- * @param rules rules to apply
+ * Applies the next batch.
*/
private Future<CompletedBatchOperation> applyNextBatch() {
if (work.isEmpty()) {
diff --git a/core/net/src/main/java/org/onlab/onos/net/intent/impl/MultiPointToSinglePointIntentCompiler.java b/core/net/src/main/java/org/onlab/onos/net/intent/impl/MultiPointToSinglePointIntentCompiler.java
index 6ce12d6..cfc8d73 100644
--- a/core/net/src/main/java/org/onlab/onos/net/intent/impl/MultiPointToSinglePointIntentCompiler.java
+++ b/core/net/src/main/java/org/onlab/onos/net/intent/impl/MultiPointToSinglePointIntentCompiler.java
@@ -1,10 +1,5 @@
package org.onlab.onos.net.intent.impl;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
-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;
@@ -13,16 +8,19 @@
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.Link;
import org.onlab.onos.net.Path;
-import org.onlab.onos.net.intent.IdGenerator;
import org.onlab.onos.net.intent.Intent;
import org.onlab.onos.net.intent.IntentCompiler;
import org.onlab.onos.net.intent.IntentExtensionService;
-import org.onlab.onos.net.intent.IntentId;
import org.onlab.onos.net.intent.LinkCollectionIntent;
import org.onlab.onos.net.intent.MultiPointToSinglePointIntent;
import org.onlab.onos.net.intent.PointToPointIntent;
import org.onlab.onos.net.topology.PathService;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
/**
* An intent compiler for
* {@link org.onlab.onos.net.intent.MultiPointToSinglePointIntent}.
@@ -37,12 +35,8 @@
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected PathService pathService;
- protected IdGenerator<IntentId> intentIdGenerator;
-
@Activate
public void activate() {
- IdBlockAllocator idBlockAllocator = new DummyIdBlockAllocator();
- intentIdGenerator = new IdBlockAllocatorBasedIntentIdGenerator(idBlockAllocator);
intentManager.registerCompiler(MultiPointToSinglePointIntent.class, this);
}
@@ -60,9 +54,9 @@
links.addAll(path.links());
}
- Intent result = new LinkCollectionIntent(intentIdGenerator.getNewId(),
- intent.selector(), intent.treatment(),
- links, intent.egressPoint());
+ Intent result = new LinkCollectionIntent(intent.appId(),
+ intent.selector(), intent.treatment(),
+ links, intent.egressPoint());
return Arrays.asList(result);
}
diff --git a/core/net/src/main/java/org/onlab/onos/net/intent/impl/ObjectiveTracker.java b/core/net/src/main/java/org/onlab/onos/net/intent/impl/ObjectiveTracker.java
index 7ba4e26..90e878e 100644
--- a/core/net/src/main/java/org/onlab/onos/net/intent/impl/ObjectiveTracker.java
+++ b/core/net/src/main/java/org/onlab/onos/net/intent/impl/ObjectiveTracker.java
@@ -11,6 +11,7 @@
import org.onlab.onos.event.Event;
import org.onlab.onos.net.Link;
import org.onlab.onos.net.LinkKey;
+import org.onlab.onos.net.NetworkResource;
import org.onlab.onos.net.intent.IntentId;
import org.onlab.onos.net.link.LinkEvent;
import org.onlab.onos.net.topology.TopologyEvent;
@@ -27,8 +28,8 @@
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Multimaps.synchronizedSetMultimap;
import static java.util.concurrent.Executors.newSingleThreadExecutor;
-import static org.onlab.onos.net.link.LinkEvent.Type.LINK_REMOVED;
import static org.onlab.onos.net.LinkKey.linkKey;
+import static org.onlab.onos.net.link.LinkEvent.Type.LINK_REMOVED;
import static org.onlab.util.Tools.namedThreads;
import static org.slf4j.LoggerFactory.getLogger;
@@ -81,16 +82,22 @@
}
@Override
- public void addTrackedResources(IntentId intentId, Collection<Link> resources) {
- for (Link link : resources) {
- intentsByLink.put(linkKey(link), intentId);
+ public void addTrackedResources(IntentId intentId,
+ Collection<NetworkResource> resources) {
+ for (NetworkResource resource : resources) {
+ if (resource instanceof Link) {
+ intentsByLink.put(linkKey((Link) resource), intentId);
+ }
}
}
@Override
- public void removeTrackedResources(IntentId intentId, Collection<Link> resources) {
- for (Link link : resources) {
- intentsByLink.remove(linkKey(link), intentId);
+ public void removeTrackedResources(IntentId intentId,
+ Collection<NetworkResource> resources) {
+ for (NetworkResource resource : resources) {
+ if (resource instanceof Link) {
+ intentsByLink.remove(linkKey((Link) resource), intentId);
+ }
}
}
diff --git a/core/net/src/main/java/org/onlab/onos/net/intent/impl/ObjectiveTrackerService.java b/core/net/src/main/java/org/onlab/onos/net/intent/impl/ObjectiveTrackerService.java
index 15496ff..9acd215 100644
--- a/core/net/src/main/java/org/onlab/onos/net/intent/impl/ObjectiveTrackerService.java
+++ b/core/net/src/main/java/org/onlab/onos/net/intent/impl/ObjectiveTrackerService.java
@@ -1,6 +1,6 @@
package org.onlab.onos.net.intent.impl;
-import org.onlab.onos.net.Link;
+import org.onlab.onos.net.NetworkResource;
import org.onlab.onos.net.intent.IntentId;
import java.util.Collection;
@@ -28,17 +28,19 @@
/**
* Adds a path flow to be tracked.
*
- * @param intentId intent identity on whose behalf the path is being tracked
+ * @param intentId intent identity on whose behalf the path is being tracked
* @param resources resources to track
*/
- public void addTrackedResources(IntentId intentId, Collection<Link> resources);
+ public void addTrackedResources(IntentId intentId,
+ Collection<NetworkResource> resources);
/**
* Removes a path flow to be tracked.
*
- * @param intentId intent identity on whose behalf the path is being tracked
+ * @param intentId intent identity on whose behalf the path is being tracked
* @param resources resources to stop tracking
*/
- public void removeTrackedResources(IntentId intentId, Collection<Link> resources);
+ public void removeTrackedResources(IntentId intentId,
+ Collection<NetworkResource> resources);
}
diff --git a/core/net/src/main/java/org/onlab/onos/net/intent/impl/PointToPointIntentCompiler.java b/core/net/src/main/java/org/onlab/onos/net/intent/impl/PointToPointIntentCompiler.java
index 0556df0..25d50cc 100644
--- a/core/net/src/main/java/org/onlab/onos/net/intent/impl/PointToPointIntentCompiler.java
+++ b/core/net/src/main/java/org/onlab/onos/net/intent/impl/PointToPointIntentCompiler.java
@@ -1,10 +1,5 @@
package org.onlab.onos.net.intent.impl;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-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;
@@ -16,16 +11,19 @@
import org.onlab.onos.net.Link;
import org.onlab.onos.net.Path;
import org.onlab.onos.net.host.HostService;
-import org.onlab.onos.net.intent.IdGenerator;
import org.onlab.onos.net.intent.Intent;
import org.onlab.onos.net.intent.IntentCompiler;
import org.onlab.onos.net.intent.IntentExtensionService;
-import org.onlab.onos.net.intent.IntentId;
import org.onlab.onos.net.intent.PathIntent;
import org.onlab.onos.net.intent.PointToPointIntent;
import org.onlab.onos.net.provider.ProviderId;
import org.onlab.onos.net.topology.PathService;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+
/**
* A intent compiler for {@link org.onlab.onos.net.intent.HostToHostIntent}.
*/
@@ -43,12 +41,8 @@
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected HostService hostService;
- protected IdGenerator<IntentId> intentIdGenerator;
-
@Activate
public void activate() {
- IdBlockAllocator idBlockAllocator = new DummyIdBlockAllocator();
- intentIdGenerator = new IdBlockAllocatorBasedIntentIdGenerator(idBlockAllocator);
intentManager.registerCompiler(PointToPointIntent.class, this);
}
@@ -67,23 +61,21 @@
links.add(DefaultEdgeLink.createEdgeLink(intent.egressPoint(), false));
return Arrays.asList(createPathIntent(new DefaultPath(PID, links, path.cost() + 2,
- path.annotations()),
- intent));
+ path.annotations()),
+ intent));
}
/**
* Creates a path intent from the specified path and original
* connectivity intent.
*
- * @param path path to create an intent for
+ * @param path path to create an intent for
* @param intent original intent
*/
private Intent createPathIntent(Path path,
PointToPointIntent intent) {
-
- return new PathIntent(intentIdGenerator.getNewId(),
- intent.selector(), intent.treatment(),
- path.src(), path.dst(), path);
+ return new PathIntent(intent.appId(),
+ intent.selector(), intent.treatment(), path);
}
/**
diff --git a/core/net/src/test/java/org/onlab/onos/net/intent/TestHostToHostIntent.java b/core/net/src/test/java/org/onlab/onos/net/intent/TestHostToHostIntent.java
index f5e2551..4ebee73 100644
--- a/core/net/src/test/java/org/onlab/onos/net/intent/TestHostToHostIntent.java
+++ b/core/net/src/test/java/org/onlab/onos/net/intent/TestHostToHostIntent.java
@@ -1,6 +1,8 @@
package org.onlab.onos.net.intent;
import org.junit.Test;
+import org.onlab.onos.ApplicationId;
+import org.onlab.onos.TestApplicationId;
import org.onlab.onos.net.HostId;
import org.onlab.onos.net.flow.TrafficSelector;
import org.onlab.onos.net.flow.TrafficTreatment;
@@ -16,15 +18,13 @@
*/
public class TestHostToHostIntent {
+ private static final ApplicationId APPID = new TestApplicationId("foo");
+
private TrafficSelector selector = new IntentTestsMocks.MockSelector();
private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment();
- private HostToHostIntent makeHostToHost(long id, HostId one, HostId two) {
- return new HostToHostIntent(new IntentId(id),
- one,
- two,
- selector,
- treatment);
+ private HostToHostIntent makeHostToHost(HostId one, HostId two) {
+ return new HostToHostIntent(APPID, one, two, selector, treatment);
}
/**
@@ -36,8 +36,8 @@
HostId one = hid("00:00:00:00:00:01/-1");
HostId two = hid("00:00:00:00:00:02/-1");
- HostToHostIntent i1 = makeHostToHost(12, one, two);
- HostToHostIntent i2 = makeHostToHost(12, one, two);
+ HostToHostIntent i1 = makeHostToHost(one, two);
+ HostToHostIntent i2 = makeHostToHost(one, two);
assertThat(i1, is(equalTo(i2)));
}
@@ -47,42 +47,25 @@
* to different Hosts. These should compare not equal.
*/
@Test
- public void testLinksDifferentEquals() {
-
+ public void testSameEquals2() {
HostId one = hid("00:00:00:00:00:01/-1");
HostId two = hid("00:00:00:00:00:02/-1");
- HostToHostIntent i1 = makeHostToHost(12, one, two);
- HostToHostIntent i2 = makeHostToHost(12, two, one);
+ HostToHostIntent i1 = makeHostToHost(one, two);
+ HostToHostIntent i2 = makeHostToHost(two, one);
- assertThat(i1, is(not(equalTo(i2))));
- }
-
- /**
- * Tests the equals() method where two HostToHostIntents have different
- * ids. These should compare not equal.
- */
-
- @Test
- public void testBaseDifferentEquals() {
- HostId one = hid("00:00:00:00:00:01/-1");
- HostId two = hid("00:00:00:00:00:02/-1");
- HostToHostIntent i1 = makeHostToHost(12, one, two);
- HostToHostIntent i2 = makeHostToHost(11, one, two);
-
- assertThat(i1, is(not(equalTo(i2))));
+ assertThat(i1, is(equalTo(i2)));
}
/**
* Tests that the hashCode() values for two equivalent HostToHostIntent
* objects are the same.
*/
-
@Test
public void testHashCodeEquals() {
HostId one = hid("00:00:00:00:00:01/-1");
HostId two = hid("00:00:00:00:00:02/-1");
- HostToHostIntent i1 = makeHostToHost(12, one, two);
- HostToHostIntent i2 = makeHostToHost(12, one, two);
+ HostToHostIntent i1 = makeHostToHost(one, two);
+ HostToHostIntent i2 = makeHostToHost(one, two);
assertThat(i1.hashCode(), is(equalTo(i2.hashCode())));
}
@@ -91,13 +74,27 @@
* Tests that the hashCode() values for two distinct LinkCollectionIntent
* objects are different.
*/
+ @Test
+ public void testHashCodeEquals2() {
+ HostId one = hid("00:00:00:00:00:01/-1");
+ HostId two = hid("00:00:00:00:00:02/-1");
+ HostToHostIntent i1 = makeHostToHost(one, two);
+ HostToHostIntent i2 = makeHostToHost(two, one);
+ assertThat(i1.hashCode(), is(equalTo(i2.hashCode())));
+ }
+
+ /**
+ * Tests that the hashCode() values for two distinct LinkCollectionIntent
+ * objects are different.
+ */
@Test
public void testHashCodeDifferent() {
HostId one = hid("00:00:00:00:00:01/-1");
HostId two = hid("00:00:00:00:00:02/-1");
- HostToHostIntent i1 = makeHostToHost(12, one, two);
- HostToHostIntent i2 = makeHostToHost(112, one, two);
+ HostId three = hid("00:00:00:00:00:32/-1");
+ HostToHostIntent i1 = makeHostToHost(one, two);
+ HostToHostIntent i2 = makeHostToHost(one, three);
assertThat(i1.hashCode(), is(not(equalTo(i2.hashCode()))));
}
diff --git a/core/net/src/test/java/org/onlab/onos/net/intent/TestLinkCollectionIntent.java b/core/net/src/test/java/org/onlab/onos/net/intent/TestLinkCollectionIntent.java
index a7082b4..65aa71f 100644
--- a/core/net/src/test/java/org/onlab/onos/net/intent/TestLinkCollectionIntent.java
+++ b/core/net/src/test/java/org/onlab/onos/net/intent/TestLinkCollectionIntent.java
@@ -11,6 +11,8 @@
import org.junit.Before;
import org.junit.Test;
+import org.onlab.onos.ApplicationId;
+import org.onlab.onos.TestApplicationId;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.Link;
@@ -23,6 +25,8 @@
*/
public class TestLinkCollectionIntent {
+ private static final ApplicationId APPID = new TestApplicationId("foo");
+
private Link link1 = link("dev1", 1, "dev2", 2);
private Link link2 = link("dev1", 1, "dev3", 2);
private Link link3 = link("dev2", 1, "dev3", 2);
@@ -38,10 +42,9 @@
private TrafficSelector selector = new IntentTestsMocks.MockSelector();
private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment();
- private LinkCollectionIntent makeLinkCollection(long id, Set<Link> links,
+ private LinkCollectionIntent makeLinkCollection(Set<Link> links,
ConnectPoint egress) {
- return new LinkCollectionIntent(new IntentId(id),
- selector, treatment, links, egress);
+ return new LinkCollectionIntent(APPID, selector, treatment, links, egress);
}
@Before
@@ -64,8 +67,8 @@
links2.add(link2);
links2.add(link1);
- LinkCollectionIntent i1 = makeLinkCollection(12, links1, egress1);
- LinkCollectionIntent i2 = makeLinkCollection(12, links2, egress1);
+ LinkCollectionIntent i1 = makeLinkCollection(links1, egress1);
+ LinkCollectionIntent i2 = makeLinkCollection(links2, egress1);
assertThat(i1, is(equalTo(i2)));
}
@@ -82,8 +85,8 @@
links2.add(link3);
links2.add(link1);
- LinkCollectionIntent i1 = makeLinkCollection(12, links1, egress1);
- LinkCollectionIntent i2 = makeLinkCollection(12, links2, egress1);
+ LinkCollectionIntent i1 = makeLinkCollection(links1, egress1);
+ LinkCollectionIntent i2 = makeLinkCollection(links2, egress1);
assertThat(i1, is(not(equalTo(i2))));
}
@@ -102,26 +105,8 @@
links2.add(link2);
links2.add(link1);
- LinkCollectionIntent i1 = makeLinkCollection(12, links1, egress1);
- LinkCollectionIntent i2 = makeLinkCollection(12, links2, egress2);
-
- assertThat(i1, is(not(equalTo(i2))));
- }
-
- /**
- * Tests the equals() method where two LinkCollectionIntents have different
- * ids. These should compare not equal.
- */
- @Test
- public void testBaseDifferentEquals() {
- links1.add(link1);
- links1.add(link2);
-
- links2.add(link2);
- links2.add(link1);
-
- LinkCollectionIntent i1 = makeLinkCollection(1, links1, egress1);
- LinkCollectionIntent i2 = makeLinkCollection(2, links2, egress1);
+ LinkCollectionIntent i1 = makeLinkCollection(links1, egress1);
+ LinkCollectionIntent i2 = makeLinkCollection(links2, egress2);
assertThat(i1, is(not(equalTo(i2))));
}
@@ -140,8 +125,8 @@
links2.add(link2);
links2.add(link1);
- LinkCollectionIntent i1 = makeLinkCollection(1, links1, egress1);
- LinkCollectionIntent i2 = makeLinkCollection(1, links2, egress1);
+ LinkCollectionIntent i1 = makeLinkCollection(links1, egress1);
+ LinkCollectionIntent i2 = makeLinkCollection(links2, egress1);
assertThat(i1.hashCode(), is(equalTo(i2.hashCode())));
}
@@ -158,8 +143,8 @@
links2.add(link1);
links2.add(link3);
- LinkCollectionIntent i1 = makeLinkCollection(1, links1, egress1);
- LinkCollectionIntent i2 = makeLinkCollection(1, links2, egress2);
+ LinkCollectionIntent i1 = makeLinkCollection(links1, egress1);
+ LinkCollectionIntent i2 = makeLinkCollection(links2, egress2);
assertThat(i1.hashCode(), is(not(equalTo(i2.hashCode()))));
}
diff --git a/core/net/src/test/java/org/onlab/onos/net/intent/TestMultiPointToSinglePointIntent.java b/core/net/src/test/java/org/onlab/onos/net/intent/TestMultiPointToSinglePointIntent.java
index e921907..09dfcb2 100644
--- a/core/net/src/test/java/org/onlab/onos/net/intent/TestMultiPointToSinglePointIntent.java
+++ b/core/net/src/test/java/org/onlab/onos/net/intent/TestMultiPointToSinglePointIntent.java
@@ -1,14 +1,16 @@
package org.onlab.onos.net.intent;
-import java.util.HashSet;
-import java.util.Set;
-
import org.junit.Before;
import org.junit.Test;
+import org.onlab.onos.ApplicationId;
+import org.onlab.onos.TestApplicationId;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.flow.TrafficSelector;
import org.onlab.onos.net.flow.TrafficTreatment;
+import java.util.HashSet;
+import java.util.Set;
+
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
@@ -20,6 +22,8 @@
*/
public class TestMultiPointToSinglePointIntent {
+ private static final ApplicationId APPID = new TestApplicationId("foo");
+
private ConnectPoint point1 = connectPoint("dev1", 1);
private ConnectPoint point2 = connectPoint("dev2", 1);
private ConnectPoint point3 = connectPoint("dev3", 1);
@@ -33,19 +37,14 @@
/**
* Creates a MultiPointToSinglePointIntent object.
*
- * @param id identifier to use for the new intent
* @param ingress set of ingress points
- * @param egress egress point
+ * @param egress egress point
* @return MultiPointToSinglePoint intent
*/
- private MultiPointToSinglePointIntent makeIntent(long id,
- Set<ConnectPoint> ingress,
- ConnectPoint egress) {
- return new MultiPointToSinglePointIntent(new IntentId(id),
- selector,
- treatment,
- ingress,
- egress);
+ private MultiPointToSinglePointIntent makeIntent(Set<ConnectPoint> ingress,
+ ConnectPoint egress) {
+ return new MultiPointToSinglePointIntent(APPID, selector, treatment,
+ ingress, egress);
}
/**
@@ -72,8 +71,8 @@
ingress2.add(point3);
ingress2.add(point2);
- Intent i1 = makeIntent(12, ingress1, point1);
- Intent i2 = makeIntent(12, ingress2, point1);
+ Intent i1 = makeIntent(ingress1, point1);
+ Intent i2 = makeIntent(ingress2, point1);
assertThat(i1, is(equalTo(i2)));
}
@@ -89,23 +88,8 @@
ingress2.add(point3);
ingress2.add(point2);
- Intent i1 = makeIntent(12, ingress1, point1);
- Intent i2 = makeIntent(12, ingress2, point1);
-
- assertThat(i1, is(not(equalTo(i2))));
- }
-
- /**
- * Tests the equals() method where two MultiPointToSinglePoint have different
- * ids. These should compare not equal.
- */
- @Test
- public void testBaseDifferentEquals() {
- ingress1.add(point3);
- ingress2.add(point3);
-
- Intent i1 = makeIntent(12, ingress1, point1);
- Intent i2 = makeIntent(11, ingress2, point1);
+ Intent i1 = makeIntent(ingress1, point1);
+ Intent i2 = makeIntent(ingress2, point1);
assertThat(i1, is(not(equalTo(i2))));
}
@@ -122,8 +106,8 @@
ingress2.add(point3);
ingress2.add(point2);
- Intent i1 = makeIntent(12, ingress1, point1);
- Intent i2 = makeIntent(12, ingress2, point1);
+ Intent i1 = makeIntent(ingress1, point1);
+ Intent i2 = makeIntent(ingress2, point1);
assertThat(i1.hashCode(), is(equalTo(i2.hashCode())));
}
@@ -139,8 +123,8 @@
ingress2.add(point3);
ingress2.add(point2);
- Intent i1 = makeIntent(12, ingress1, point1);
- Intent i2 = makeIntent(12, ingress2, point1);
+ Intent i1 = makeIntent(ingress1, point1);
+ Intent i2 = makeIntent(ingress2, point1);
assertThat(i1.hashCode(), is(not(equalTo(i2.hashCode()))));
diff --git a/core/net/src/test/java/org/onlab/onos/net/intent/TestPointToPointIntent.java b/core/net/src/test/java/org/onlab/onos/net/intent/TestPointToPointIntent.java
index 41769c6..e34d7ce 100644
--- a/core/net/src/test/java/org/onlab/onos/net/intent/TestPointToPointIntent.java
+++ b/core/net/src/test/java/org/onlab/onos/net/intent/TestPointToPointIntent.java
@@ -1,14 +1,14 @@
package org.onlab.onos.net.intent;
import org.junit.Test;
+import org.onlab.onos.ApplicationId;
+import org.onlab.onos.TestApplicationId;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.flow.TrafficSelector;
import org.onlab.onos.net.flow.TrafficTreatment;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.*;
import static org.onlab.onos.net.NetTestTools.connectPoint;
/**
@@ -16,20 +16,17 @@
*/
public class TestPointToPointIntent {
+ private static final ApplicationId APPID = new TestApplicationId("foo");
+
private TrafficSelector selector = new IntentTestsMocks.MockSelector();
private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment();
private ConnectPoint point1 = connectPoint("dev1", 1);
private ConnectPoint point2 = connectPoint("dev2", 1);
- private PointToPointIntent makePointToPoint(long id,
- ConnectPoint ingress,
+ private PointToPointIntent makePointToPoint(ConnectPoint ingress,
ConnectPoint egress) {
- return new PointToPointIntent(new IntentId(id),
- selector,
- treatment,
- ingress,
- egress);
+ return new PointToPointIntent(APPID, selector, treatment, ingress, egress);
}
/**
@@ -38,8 +35,8 @@
*/
@Test
public void testSameEquals() {
- PointToPointIntent i1 = makePointToPoint(12, point1, point2);
- PointToPointIntent i2 = makePointToPoint(12, point1, point2);
+ PointToPointIntent i1 = makePointToPoint(point1, point2);
+ PointToPointIntent i2 = makePointToPoint(point1, point2);
assertThat(i1, is(equalTo(i2)));
}
@@ -50,22 +47,8 @@
*/
@Test
public void testLinksDifferentEquals() {
-
- PointToPointIntent i1 = makePointToPoint(12, point1, point2);
- PointToPointIntent i2 = makePointToPoint(12, point2, point1);
-
- assertThat(i1, is(not(equalTo(i2))));
- }
-
- /**
- * Tests the equals() method where two HostToHostIntents have different
- * ids. These should compare not equal.
- */
- @Test
- public void testBaseDifferentEquals() {
- PointToPointIntent i1 = makePointToPoint(12, point1, point2);
- PointToPointIntent i2 = makePointToPoint(11, point1, point2);
-
+ PointToPointIntent i1 = makePointToPoint(point1, point2);
+ PointToPointIntent i2 = makePointToPoint(point2, point1);
assertThat(i1, is(not(equalTo(i2))));
}
@@ -76,8 +59,8 @@
*/
@Test
public void testHashCodeEquals() {
- PointToPointIntent i1 = makePointToPoint(12, point1, point2);
- PointToPointIntent i2 = makePointToPoint(12, point1, point2);
+ PointToPointIntent i1 = makePointToPoint(point1, point2);
+ PointToPointIntent i2 = makePointToPoint(point1, point2);
assertThat(i1.hashCode(), is(equalTo(i2.hashCode())));
}
@@ -88,8 +71,8 @@
*/
@Test
public void testHashCodeDifferent() {
- PointToPointIntent i1 = makePointToPoint(12, point1, point2);
- PointToPointIntent i2 = makePointToPoint(22, point1, point2);
+ PointToPointIntent i1 = makePointToPoint(point1, point2);
+ PointToPointIntent i2 = makePointToPoint(point2, point1);
assertThat(i1.hashCode(), is(not(equalTo(i2.hashCode()))));
}
diff --git a/core/net/src/test/java/org/onlab/onos/net/intent/impl/TestHostToHostIntentCompiler.java b/core/net/src/test/java/org/onlab/onos/net/intent/impl/TestHostToHostIntentCompiler.java
index bd61b7a..e853a29 100644
--- a/core/net/src/test/java/org/onlab/onos/net/intent/impl/TestHostToHostIntentCompiler.java
+++ b/core/net/src/test/java/org/onlab/onos/net/intent/impl/TestHostToHostIntentCompiler.java
@@ -1,10 +1,10 @@
package org.onlab.onos.net.intent.impl;
-import java.util.List;
-
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Test;
+import org.onlab.onos.ApplicationId;
+import org.onlab.onos.TestApplicationId;
import org.onlab.onos.net.Host;
import org.onlab.onos.net.HostId;
import org.onlab.onos.net.flow.TrafficSelector;
@@ -12,16 +12,14 @@
import org.onlab.onos.net.host.HostService;
import org.onlab.onos.net.intent.HostToHostIntent;
import org.onlab.onos.net.intent.Intent;
-import org.onlab.onos.net.intent.IntentId;
import org.onlab.onos.net.intent.IntentTestsMocks;
import org.onlab.onos.net.intent.PathIntent;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.eq;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
+import java.util.List;
+
+import static org.easymock.EasyMock.*;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
@@ -40,6 +38,8 @@
private static final String HOST_ONE = HOST_ONE_MAC + "/" + HOST_ONE_VLAN;
private static final String HOST_TWO = HOST_TWO_MAC + "/" + HOST_TWO_VLAN;
+ private static final ApplicationId APPID = new TestApplicationId("foo");
+
private TrafficSelector selector = new IntentTestsMocks.MockSelector();
private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment();
@@ -73,11 +73,8 @@
* @return HostToHostIntent for the two hosts
*/
private HostToHostIntent makeIntent(String oneIdString, String twoIdString) {
- return new HostToHostIntent(new IntentId(12),
- hid(oneIdString),
- hid(twoIdString),
- selector,
- treatment);
+ return new HostToHostIntent(APPID, hid(oneIdString), hid(twoIdString),
+ selector, treatment);
}
/**
@@ -91,9 +88,6 @@
new HostToHostIntentCompiler();
compiler.pathService = new IntentTestsMocks.MockPathService(hops);
compiler.hostService = mockHostService;
- IdBlockAllocator idBlockAllocator = new DummyIdBlockAllocator();
- compiler.intentIdGenerator =
- new IdBlockAllocatorBasedIntentIdGenerator(idBlockAllocator);
return compiler;
}
diff --git a/core/net/src/test/java/org/onlab/onos/net/intent/impl/TestMultiPointToSinglePointIntentCompiler.java b/core/net/src/test/java/org/onlab/onos/net/intent/impl/TestMultiPointToSinglePointIntentCompiler.java
index 8d286cf..1c78e26 100644
--- a/core/net/src/test/java/org/onlab/onos/net/intent/impl/TestMultiPointToSinglePointIntentCompiler.java
+++ b/core/net/src/test/java/org/onlab/onos/net/intent/impl/TestMultiPointToSinglePointIntentCompiler.java
@@ -1,24 +1,25 @@
package org.onlab.onos.net.intent.impl;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
import org.hamcrest.Matchers;
import org.junit.Test;
+import org.onlab.onos.ApplicationId;
+import org.onlab.onos.TestApplicationId;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.ElementId;
import org.onlab.onos.net.Path;
import org.onlab.onos.net.flow.TrafficSelector;
import org.onlab.onos.net.flow.TrafficTreatment;
import org.onlab.onos.net.intent.Intent;
-import org.onlab.onos.net.intent.IntentId;
import org.onlab.onos.net.intent.IntentTestsMocks;
import org.onlab.onos.net.intent.LinkCollectionIntent;
import org.onlab.onos.net.intent.MultiPointToSinglePointIntent;
import org.onlab.onos.net.topology.LinkWeight;
import org.onlab.onos.net.topology.PathService;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
@@ -32,6 +33,8 @@
*/
public class TestMultiPointToSinglePointIntentCompiler {
+ private static final ApplicationId APPID = new TestApplicationId("foo");
+
private TrafficSelector selector = new IntentTestsMocks.MockSelector();
private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment();
@@ -74,7 +77,7 @@
* and an egress point.
*
* @param ingressIds array of ingress device ids
- * @param egressId device id of the egress point
+ * @param egressId device id of the egress point
* @return MultiPointToSinglePoint intent
*/
private MultiPointToSinglePointIntent makeIntent(String[] ingressIds, String egressId) {
@@ -82,15 +85,11 @@
ConnectPoint egressPoint = connectPoint(egressId, 1);
for (String ingressId : ingressIds) {
- ingressPoints.add(connectPoint(ingressId, 1));
+ ingressPoints.add(connectPoint(ingressId, 1));
}
- return new MultiPointToSinglePointIntent(
- new IntentId(12),
- selector,
- treatment,
- ingressPoints,
- egressPoint);
+ return new MultiPointToSinglePointIntent(APPID, selector, treatment,
+ ingressPoints, egressPoint);
}
/**
@@ -103,9 +102,6 @@
MultiPointToSinglePointIntentCompiler compiler =
new MultiPointToSinglePointIntentCompiler();
compiler.pathService = new MockPathService(hops);
- IdBlockAllocator idBlockAllocator = new DummyIdBlockAllocator();
- compiler.intentIdGenerator =
- new IdBlockAllocatorBasedIntentIdGenerator(idBlockAllocator);
return compiler;
}
@@ -122,7 +118,7 @@
assertThat(intent, is(notNullValue()));
String[] hops = {"h1", "h2", "h3", "h4", "h5", "h6", "h7", "h8",
- egress};
+ egress};
MultiPointToSinglePointIntentCompiler compiler = makeCompiler(hops);
assertThat(compiler, is(notNullValue()));
@@ -184,7 +180,7 @@
@Test
public void testMultiIngressCompilation() {
String[] ingress = {"i1", "i2", "i3", "i4", "i5",
- "i6", "i7", "i8", "i9", "i10"};
+ "i6", "i7", "i8", "i9", "i10"};
String egress = "e";
MultiPointToSinglePointIntent intent = makeIntent(ingress, egress);
diff --git a/core/net/src/test/java/org/onlab/onos/net/intent/impl/TestPointToPointIntentCompiler.java b/core/net/src/test/java/org/onlab/onos/net/intent/impl/TestPointToPointIntentCompiler.java
index e282347..5b50a22 100644
--- a/core/net/src/test/java/org/onlab/onos/net/intent/impl/TestPointToPointIntentCompiler.java
+++ b/core/net/src/test/java/org/onlab/onos/net/intent/impl/TestPointToPointIntentCompiler.java
@@ -1,17 +1,18 @@
package org.onlab.onos.net.intent.impl;
-import java.util.List;
-
import org.hamcrest.Matchers;
import org.junit.Test;
+import org.onlab.onos.ApplicationId;
+import org.onlab.onos.TestApplicationId;
import org.onlab.onos.net.flow.TrafficSelector;
import org.onlab.onos.net.flow.TrafficTreatment;
import org.onlab.onos.net.intent.Intent;
-import org.onlab.onos.net.intent.IntentId;
import org.onlab.onos.net.intent.IntentTestsMocks;
import org.onlab.onos.net.intent.PathIntent;
import org.onlab.onos.net.intent.PointToPointIntent;
+import java.util.List;
+
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
@@ -24,6 +25,8 @@
*/
public class TestPointToPointIntentCompiler {
+ private static final ApplicationId APPID = new TestApplicationId("foo");
+
private TrafficSelector selector = new IntentTestsMocks.MockSelector();
private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment();
@@ -31,14 +34,12 @@
* Creates a PointToPoint intent based on ingress and egress device Ids.
*
* @param ingressIdString string for id of ingress device
- * @param egressIdString string for id of egress device
+ * @param egressIdString string for id of egress device
* @return PointToPointIntent for the two devices
*/
private PointToPointIntent makeIntent(String ingressIdString,
String egressIdString) {
- return new PointToPointIntent(new IntentId(12),
- selector,
- treatment,
+ return new PointToPointIntent(APPID, selector, treatment,
connectPoint(ingressIdString, 1),
connectPoint(egressIdString, 1));
}
@@ -53,9 +54,6 @@
PointToPointIntentCompiler compiler =
new PointToPointIntentCompiler();
compiler.pathService = new IntentTestsMocks.MockPathService(hops);
- IdBlockAllocator idBlockAllocator = new DummyIdBlockAllocator();
- compiler.intentIdGenerator =
- new IdBlockAllocatorBasedIntentIdGenerator(idBlockAllocator);
return compiler;
}
diff --git a/core/store/dist/src/main/java/org/onlab/onos/store/flow/impl/DistributedFlowRuleStore.java b/core/store/dist/src/main/java/org/onlab/onos/store/flow/impl/DistributedFlowRuleStore.java
index e5b2ed6..3da5d25 100644
--- a/core/store/dist/src/main/java/org/onlab/onos/store/flow/impl/DistributedFlowRuleStore.java
+++ b/core/store/dist/src/main/java/org/onlab/onos/store/flow/impl/DistributedFlowRuleStore.java
@@ -2,6 +2,7 @@
import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_REMOVED;
import static org.slf4j.LoggerFactory.getLogger;
+import static org.onlab.onos.store.flow.impl.FlowStoreMessageSubjects.*;
import java.io.IOException;
import java.util.Collection;
@@ -30,6 +31,7 @@
import org.onlab.onos.store.AbstractStore;
import org.onlab.onos.store.cluster.messaging.ClusterCommunicationService;
import org.onlab.onos.store.cluster.messaging.ClusterMessage;
+import org.onlab.onos.store.cluster.messaging.ClusterMessageHandler;
import org.onlab.onos.store.cluster.messaging.ClusterMessageResponse;
import org.onlab.onos.store.flow.ReplicaInfo;
import org.onlab.onos.store.flow.ReplicaInfoService;
@@ -80,10 +82,44 @@
};
// TODO: make this configurable
- private static final long FLOW_RULE_STORE_TIMEOUT_MILLIS = 1000;
+ private static final long FLOW_RULE_STORE_TIMEOUT_MILLIS = 5000;
@Activate
public void activate() {
+ clusterCommunicator.addSubscriber(STORE_FLOW_RULE, new ClusterMessageHandler() {
+
+ @Override
+ public void handle(ClusterMessage message) {
+ FlowRule rule = SERIALIZER.decode(message.payload());
+ log.info("received add request for {}", rule);
+ storeFlowEntryInternal(rule);
+ // FIXME what to respond.
+ try {
+ // FIXME: #respond() not working. responded message is
+ // handled by this sender node and never goes back.
+ message.respond(SERIALIZER.encode("ACK"));
+ } catch (IOException e) {
+ log.error("Failed to respond back", e);
+ }
+ }
+ });
+
+ clusterCommunicator.addSubscriber(DELETE_FLOW_RULE, new ClusterMessageHandler() {
+
+ @Override
+ public void handle(ClusterMessage message) {
+ FlowRule rule = SERIALIZER.decode(message.payload());
+ log.info("received delete request for {}", rule);
+ deleteFlowRuleInternal(rule);
+ // FIXME what to respond.
+ try {
+ message.respond(SERIALIZER.encode("ACK"));
+ } catch (IOException e) {
+ log.error("Failed to respond back", e);
+ }
+
+ }
+ });
log.info("Started");
}
@@ -131,13 +167,14 @@
}
@Override
- public void storeFlowRule(FlowRule rule) {
+ public boolean storeFlowRule(FlowRule rule) {
ReplicaInfo replicaInfo = replicaInfoManager.getReplicaInfoFor(rule.deviceId());
if (replicaInfo.master().get().equals(clusterService.getLocalNode().id())) {
- storeFlowEntryInternal(rule);
- return;
+ return storeFlowEntryInternal(rule);
}
+ log.warn("Not my flow forwarding to {}", replicaInfo.master().orNull());
+
ClusterMessage message = new ClusterMessage(
clusterService.getLocalNode().id(),
FlowStoreMessageSubjects.STORE_FLOW_RULE,
@@ -150,26 +187,29 @@
// FIXME: throw a FlowStoreException
throw new RuntimeException(e);
}
+ return false;
}
- private synchronized void storeFlowEntryInternal(FlowRule flowRule) {
+ private synchronized boolean storeFlowEntryInternal(FlowRule flowRule) {
StoredFlowEntry flowEntry = new DefaultFlowEntry(flowRule);
DeviceId deviceId = flowRule.deviceId();
// write to local copy.
if (!flowEntries.containsEntry(deviceId, flowEntry)) {
flowEntries.put(deviceId, flowEntry);
flowEntriesById.put(flowRule.appId(), flowEntry);
+ notifyDelegate(new FlowRuleEvent(Type.RULE_ADD_REQUESTED, flowRule));
+ return true;
}
// write to backup.
// TODO: write to a hazelcast map.
+ return false;
}
@Override
- public synchronized void deleteFlowRule(FlowRule rule) {
+ public synchronized boolean deleteFlowRule(FlowRule rule) {
ReplicaInfo replicaInfo = replicaInfoManager.getReplicaInfoFor(rule.deviceId());
if (replicaInfo.master().get().equals(clusterService.getLocalNode().id())) {
- deleteFlowRuleInternal(rule);
- return;
+ return deleteFlowRuleInternal(rule);
}
ClusterMessage message = new ClusterMessage(
@@ -184,15 +224,21 @@
// FIXME: throw a FlowStoreException
throw new RuntimeException(e);
}
+ return false;
}
- private synchronized void deleteFlowRuleInternal(FlowRule flowRule) {
+ private synchronized boolean deleteFlowRuleInternal(FlowRule flowRule) {
StoredFlowEntry entry = getFlowEntryInternal(flowRule);
if (entry == null) {
- return;
+ return false;
}
entry.setState(FlowEntryState.PENDING_REMOVE);
+
// TODO: also update backup.
+
+ notifyDelegate(new FlowRuleEvent(Type.RULE_REMOVE_REQUESTED, flowRule));
+
+ return true;
}
@Override
diff --git a/core/store/dist/src/main/java/org/onlab/onos/store/intent/impl/DistributedIntentStore.java b/core/store/dist/src/main/java/org/onlab/onos/store/intent/impl/DistributedIntentStore.java
new file mode 100644
index 0000000..0deccfb
--- /dev/null
+++ b/core/store/dist/src/main/java/org/onlab/onos/store/intent/impl/DistributedIntentStore.java
@@ -0,0 +1,108 @@
+package org.onlab.onos.store.intent.impl;
+
+import com.google.common.collect.ImmutableSet;
+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.Service;
+import org.onlab.onos.net.intent.Intent;
+import org.onlab.onos.net.intent.IntentEvent;
+import org.onlab.onos.net.intent.IntentId;
+import org.onlab.onos.net.intent.IntentState;
+import org.onlab.onos.net.intent.IntentStore;
+import org.onlab.onos.net.intent.IntentStoreDelegate;
+import org.onlab.onos.store.AbstractStore;
+import org.slf4j.Logger;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import static org.onlab.onos.net.intent.IntentState.*;
+import static org.slf4j.LoggerFactory.getLogger;
+
+//FIXME: I LIE I AM NOT DISTRIBUTED
+@Component(immediate = true)
+@Service
+public class DistributedIntentStore
+ extends AbstractStore<IntentEvent, IntentStoreDelegate>
+ implements IntentStore {
+
+ private final Logger log = getLogger(getClass());
+ private final Map<IntentId, Intent> intents = new ConcurrentHashMap<>();
+ private final Map<IntentId, IntentState> states = new ConcurrentHashMap<>();
+ private final Map<IntentId, List<Intent>> installable = new ConcurrentHashMap<>();
+
+ @Activate
+ public void activate() {
+ log.info("Started");
+ }
+
+ @Deactivate
+ public void deactivate() {
+ log.info("Stopped");
+ }
+
+ @Override
+ public IntentEvent createIntent(Intent intent) {
+ intents.put(intent.id(), intent);
+ return this.setState(intent, IntentState.SUBMITTED);
+ }
+
+ @Override
+ public IntentEvent removeIntent(IntentId intentId) {
+ Intent intent = intents.remove(intentId);
+ installable.remove(intentId);
+ IntentEvent event = this.setState(intent, WITHDRAWN);
+ states.remove(intentId);
+ return event;
+ }
+
+ @Override
+ public long getIntentCount() {
+ return intents.size();
+ }
+
+ @Override
+ public Iterable<Intent> getIntents() {
+ return ImmutableSet.copyOf(intents.values());
+ }
+
+ @Override
+ public Intent getIntent(IntentId intentId) {
+ return intents.get(intentId);
+ }
+
+ @Override
+ public IntentState getIntentState(IntentId id) {
+ return states.get(id);
+ }
+
+ @Override
+ public IntentEvent setState(Intent intent, IntentState state) {
+ IntentId id = intent.id();
+ states.put(id, state);
+ IntentEvent.Type type = (state == SUBMITTED ? IntentEvent.Type.SUBMITTED :
+ (state == INSTALLED ? IntentEvent.Type.INSTALLED :
+ (state == FAILED ? IntentEvent.Type.FAILED :
+ state == WITHDRAWN ? IntentEvent.Type.WITHDRAWN :
+ null)));
+ return type == null ? null : new IntentEvent(type, intent);
+ }
+
+ @Override
+ public void addInstallableIntents(IntentId intentId, List<Intent> result) {
+ installable.put(intentId, result);
+ }
+
+ @Override
+ public List<Intent> getInstallableIntents(IntentId intentId) {
+ return installable.get(intentId);
+ }
+
+ @Override
+ public void removeInstalledIntents(IntentId intentId) {
+ installable.remove(intentId);
+ }
+
+}
diff --git a/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/KryoNamespaces.java b/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/KryoNamespaces.java
index 38214d3..9de6d8c 100644
--- a/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/KryoNamespaces.java
+++ b/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/KryoNamespaces.java
@@ -8,6 +8,7 @@
import org.onlab.onos.cluster.ControllerNode;
import org.onlab.onos.cluster.DefaultControllerNode;
import org.onlab.onos.cluster.NodeId;
+import org.onlab.onos.cluster.RoleInfo;
import org.onlab.onos.mastership.MastershipTerm;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.DefaultAnnotations;
@@ -26,7 +27,12 @@
import org.onlab.onos.net.device.DefaultDeviceDescription;
import org.onlab.onos.net.device.DefaultPortDescription;
import org.onlab.onos.net.flow.DefaultFlowRule;
+import org.onlab.onos.net.flow.DefaultTrafficSelector;
+import org.onlab.onos.net.flow.DefaultTrafficTreatment;
import org.onlab.onos.net.flow.FlowId;
+import org.onlab.onos.net.flow.criteria.Criteria;
+import org.onlab.onos.net.flow.criteria.Criterion;
+import org.onlab.onos.net.flow.instructions.Instructions;
import org.onlab.onos.net.host.DefaultHostDescription;
import org.onlab.onos.net.host.HostDescription;
import org.onlab.onos.net.link.DefaultLinkDescription;
@@ -88,7 +94,22 @@
HostDescription.class,
DefaultHostDescription.class,
DefaultFlowRule.class,
- FlowId.class
+ FlowId.class,
+ DefaultTrafficSelector.class,
+ Criteria.PortCriterion.class,
+ Criteria.EthCriterion.class,
+ Criteria.EthTypeCriterion.class,
+ Criteria.IPCriterion.class,
+ Criteria.IPProtocolCriterion.class,
+ Criteria.VlanIdCriterion.class,
+ Criteria.VlanPcpCriterion.class,
+ Criteria.TcpPortCriterion.class,
+ Criterion.class,
+ Criterion.Type.class,
+ DefaultTrafficTreatment.class,
+ Instructions.DropInstruction.class,
+ Instructions.OutputInstruction.class,
+ RoleInfo.class
)
.register(URI.class, new URISerializer())
.register(NodeId.class, new NodeIdSerializer())
diff --git a/core/store/serializers/src/test/java/org/onlab/onos/store/serializers/KryoSerializerTest.java b/core/store/serializers/src/test/java/org/onlab/onos/store/serializers/KryoSerializerTest.java
index f76513d..1bd2097 100644
--- a/core/store/serializers/src/test/java/org/onlab/onos/store/serializers/KryoSerializerTest.java
+++ b/core/store/serializers/src/test/java/org/onlab/onos/store/serializers/KryoSerializerTest.java
@@ -3,6 +3,7 @@
import static org.junit.Assert.assertEquals;
import static org.onlab.onos.net.DeviceId.deviceId;
import static org.onlab.onos.net.PortNumber.portNumber;
+import static java.util.Arrays.asList;
import java.nio.ByteBuffer;
@@ -11,6 +12,7 @@
import org.junit.BeforeClass;
import org.junit.Test;
import org.onlab.onos.cluster.NodeId;
+import org.onlab.onos.cluster.RoleInfo;
import org.onlab.onos.mastership.MastershipTerm;
import org.onlab.onos.net.Annotations;
import org.onlab.onos.net.ConnectPoint;
@@ -198,6 +200,12 @@
}
@Test
+ public void testRoleInfo() {
+ testSerialized(new RoleInfo(new NodeId("master"),
+ asList(new NodeId("stby1"), new NodeId("stby2"))));
+ }
+
+ @Test
public void testAnnotations() {
// Annotations does not have equals defined, manually test equality
final byte[] a1Bytes = serializer.encode(A1);
diff --git a/core/store/trivial/src/main/java/org/onlab/onos/store/trivial/impl/SimpleFlowRuleStore.java b/core/store/trivial/src/main/java/org/onlab/onos/store/trivial/impl/SimpleFlowRuleStore.java
index 33ba95b..a96cacb 100644
--- a/core/store/trivial/src/main/java/org/onlab/onos/store/trivial/impl/SimpleFlowRuleStore.java
+++ b/core/store/trivial/src/main/java/org/onlab/onos/store/trivial/impl/SimpleFlowRuleStore.java
@@ -148,8 +148,9 @@
}
@Override
- public void storeFlowRule(FlowRule rule) {
+ public boolean storeFlowRule(FlowRule rule) {
final boolean added = storeFlowRuleInternal(rule);
+ return added;
}
private boolean storeFlowRuleInternal(FlowRule rule) {
@@ -166,13 +167,14 @@
}
// new flow rule added
existing.add(f);
- // TODO: notify through delegate about remote event?
+ // TODO: Should we notify only if it's "remote" event?
+ //notifyDelegate(new FlowRuleEvent(Type.RULE_ADD_REQUESTED, rule));
return true;
}
}
@Override
- public void deleteFlowRule(FlowRule rule) {
+ public boolean deleteFlowRule(FlowRule rule) {
List<StoredFlowEntry> entries = getFlowEntries(rule.deviceId(), rule.id());
synchronized (entries) {
@@ -180,12 +182,15 @@
if (entry.equals(rule)) {
synchronized (entry) {
entry.setState(FlowEntryState.PENDING_REMOVE);
- return;
+ // TODO: Should we notify only if it's "remote" event?
+ //notifyDelegate(new FlowRuleEvent(Type.RULE_REMOVE_REQUESTED, rule));
+ return true;
}
}
}
}
//log.warn("Cannot find rule {}", rule);
+ return false;
}
@Override
diff --git a/core/store/trivial/src/main/java/org/onlab/onos/store/trivial/impl/SimpleIntentStore.java b/core/store/trivial/src/main/java/org/onlab/onos/store/trivial/impl/SimpleIntentStore.java
index c7f656a..0ec8612 100644
--- a/core/store/trivial/src/main/java/org/onlab/onos/store/trivial/impl/SimpleIntentStore.java
+++ b/core/store/trivial/src/main/java/org/onlab/onos/store/trivial/impl/SimpleIntentStore.java
@@ -1,20 +1,10 @@
package org.onlab.onos.store.trivial.impl;
-import static org.onlab.onos.net.intent.IntentState.FAILED;
-import static org.onlab.onos.net.intent.IntentState.INSTALLED;
-import static org.onlab.onos.net.intent.IntentState.SUBMITTED;
-import static org.onlab.onos.net.intent.IntentState.WITHDRAWN;
-import static org.slf4j.LoggerFactory.getLogger;
-
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
+import com.google.common.collect.ImmutableSet;
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.Service;
-import org.onlab.onos.net.intent.InstallableIntent;
import org.onlab.onos.net.intent.Intent;
import org.onlab.onos.net.intent.IntentEvent;
import org.onlab.onos.net.intent.IntentId;
@@ -24,7 +14,12 @@
import org.onlab.onos.store.AbstractStore;
import org.slf4j.Logger;
-import com.google.common.collect.ImmutableSet;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import static org.onlab.onos.net.intent.IntentState.*;
+import static org.slf4j.LoggerFactory.getLogger;
@Component(immediate = true)
@Service
@@ -35,7 +30,7 @@
private final Logger log = getLogger(getClass());
private final Map<IntentId, Intent> intents = new ConcurrentHashMap<>();
private final Map<IntentId, IntentState> states = new ConcurrentHashMap<>();
- private final Map<IntentId, List<InstallableIntent>> installable =
+ private final Map<IntentId, List<Intent>> installable =
new ConcurrentHashMap<>();
@Activate
@@ -96,12 +91,12 @@
}
@Override
- public void addInstallableIntents(IntentId intentId, List<InstallableIntent> result) {
+ public void addInstallableIntents(IntentId intentId, List<Intent> result) {
installable.put(intentId, result);
}
@Override
- public List<InstallableIntent> getInstallableIntents(IntentId intentId) {
+ public List<Intent> getInstallableIntents(IntentId intentId) {
return installable.get(intentId);
}
diff --git a/pom.xml b/pom.xml
index 40b872c..47dc489 100644
--- a/pom.xml
+++ b/pom.xml
@@ -572,7 +572,7 @@
<group>
<title>Sample Applications</title>
<packages>
- org.onlab.onos.tvue:org.onlab.onos.fwd:org.onlab.onos.ifwd:org.onlab.onos.mobility:org.onlab.onos.proxyarp:org.onlab.onos.foo:org.onlab.onos.calendar
+ org.onlab.onos.tvue:org.onlab.onos.fwd:org.onlab.onos.ifwd:org.onlab.onos.mobility:org.onlab.onos.proxyarp:org.onlab.onos.foo:org.onlab.onos.calendar:org.onlab.onos.sdnip:org.onlab.onos.sdnip.*:org.onlab.onos.optical:org.onlab.onos.optical.*
</packages>
</group>
</groups>
diff --git a/utils/misc/src/main/java/org/onlab/util/KryoNamespace.java b/utils/misc/src/main/java/org/onlab/util/KryoNamespace.java
index 42d801b..1bfe3bc 100644
--- a/utils/misc/src/main/java/org/onlab/util/KryoNamespace.java
+++ b/utils/misc/src/main/java/org/onlab/util/KryoNamespace.java
@@ -171,6 +171,7 @@
Kryo kryo = getKryo();
try {
kryo.writeClassAndObject(out, obj);
+ out.flush();
return out.toBytes();
} finally {
putKryo(kryo);
@@ -188,6 +189,7 @@
Kryo kryo = getKryo();
try {
kryo.writeClassAndObject(out, obj);
+ out.flush();
} finally {
putKryo(kryo);
}