Toggle navigation
Toggle navigation
This project
Loading...
Sign in
홍길동
/
onos
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Thomas Vachuska
2014-10-20 23:31:12 -0700
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
b97cf28766a0bde5c1018d5613e387341e9c056c
b97cf287
1 parent
1c184f1d
Refactoring intent API.
Hide whitespace changes
Inline
Side-by-side
Showing
28 changed files
with
440 additions
and
576 deletions
apps/ifwd/src/main/java/org/onlab/onos/ifwd/IntentReactiveForwarding.java
apps/sdnip/src/main/java/org/onlab/onos/sdnip/PeerConnectivityManager.java
apps/sdnip/src/main/java/org/onlab/onos/sdnip/Router.java
apps/sdnip/src/main/java/org/onlab/onos/sdnip/SdnIp.java
apps/sdnip/src/test/java/org/onlab/onos/sdnip/PeerConnectivityManagerTest.java
cli/src/main/java/org/onlab/onos/cli/AbstractShellCommand.java
cli/src/main/java/org/onlab/onos/cli/net/AddHostToHostIntentCommand.java
cli/src/main/java/org/onlab/onos/cli/net/AddMultiPointToSinglePointIntentCommand.java
cli/src/main/java/org/onlab/onos/cli/net/AddPointToPointIntentCommand.java
cli/src/main/java/org/onlab/onos/cli/net/IntentPushTestCommand.java
cli/src/main/java/org/onlab/onos/cli/net/IntentRemoveCommand.java
core/api/src/main/java/org/onlab/onos/net/intent/IntentId.java
core/net/src/main/java/org/onlab/onos/impl/CoreManager.java
core/net/src/main/java/org/onlab/onos/net/intent/impl/HostToHostIntentCompiler.java
core/net/src/main/java/org/onlab/onos/net/intent/impl/IdBlockAllocatorBasedIntentIdGenerator.java
core/net/src/main/java/org/onlab/onos/net/intent/impl/IntentManager.java
core/net/src/main/java/org/onlab/onos/net/intent/impl/MultiPointToSinglePointIntentCompiler.java
core/net/src/main/java/org/onlab/onos/net/intent/impl/ObjectiveTracker.java
core/net/src/main/java/org/onlab/onos/net/intent/impl/ObjectiveTrackerService.java
core/net/src/main/java/org/onlab/onos/net/intent/impl/PointToPointIntentCompiler.java
core/net/src/test/java/org/onlab/onos/net/intent/TestHostToHostIntent.java
core/net/src/test/java/org/onlab/onos/net/intent/TestLinkCollectionIntent.java
core/net/src/test/java/org/onlab/onos/net/intent/TestMultiPointToSinglePointIntent.java
core/net/src/test/java/org/onlab/onos/net/intent/TestPointToPointIntent.java
core/net/src/test/java/org/onlab/onos/net/intent/impl/TestHostToHostIntentCompiler.java
core/net/src/test/java/org/onlab/onos/net/intent/impl/TestMultiPointToSinglePointIntentCompiler.java
core/net/src/test/java/org/onlab/onos/net/intent/impl/TestPointToPointIntentCompiler.java
core/store/dist/src/main/java/org/onlab/onos/store/intent/impl/DistributedIntentStore.java
apps/ifwd/src/main/java/org/onlab/onos/ifwd/IntentReactiveForwarding.java
View file @
b97cf28
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.TrafficSelector;
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.onos.net.topology.TopologyService;
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 @@ public class IntentReactiveForwarding {
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 @@ public class IntentReactiveForwarding {
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 @@ public class IntentReactiveForwarding {
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
);
}
...
...
apps/sdnip/src/main/java/org/onlab/onos/sdnip/PeerConnectivityManager.java
View file @
b97cf28
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.onlab.packet.IpPrefix;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.List
;
/**
* Manages the connectivity requirements between peers.
*/
...
...
@@ -38,11 +38,13 @@ public class PeerConnectivityManager {
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 @@ public class PeerConnectivityManager {
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 @@ public class PeerConnectivityManager {
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 @@ public class PeerConnectivityManager {
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 @@ public class PeerConnectivityManager {
}
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 @@ public class PeerConnectivityManager {
// 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 @@ public class PeerConnectivityManager {
TrafficTreatment
treatment
=
DefaultTrafficTreatment
.
builder
()
.
build
();
PointToPointIntent
intentMatchDstTcpPort
=
new
PointToPointIntent
(
ne
xtIntentId
()
,
selector
,
treatment
,
bgpdConnectPoint
,
bgpdPeerConnectPoint
);
PointToPointIntent
intentMatchDstTcpPort
=
ne
w
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 @@ public class PeerConnectivityManager {
.
matchTcpSrc
(
BGP_PORT
)
.
build
();
PointToPointIntent
intentMatchSrcTcpPort
=
new
PointToPointIntent
(
ne
xtIntentId
()
,
selector
,
treatment
,
bgpdConnectPoint
,
bgpdPeerConnectPoint
);
PointToPointIntent
intentMatchSrcTcpPort
=
ne
w
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 @@ public class PeerConnectivityManager {
.
matchTcpDst
(
BGP_PORT
)
.
build
();
PointToPointIntent
reversedIntentMatchDstTcpPort
=
new
PointToPointIntent
(
ne
xtIntentId
()
,
selector
,
treatment
,
bgpdPeerConnectPoint
,
bgpdConnectPoint
);
PointToPointIntent
reversedIntentMatchDstTcpPort
=
ne
w
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 @@ public class PeerConnectivityManager {
.
matchTcpSrc
(
BGP_PORT
)
.
build
();
PointToPointIntent
reversedIntentMatchSrcTcpPort
=
new
PointToPointIntent
(
ne
xtIntentId
()
,
selector
,
treatment
,
bgpdPeerConnectPoint
,
bgpdConnectPoint
);
PointToPointIntent
reversedIntentMatchSrcTcpPort
=
ne
w
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 @@ public class PeerConnectivityManager {
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 @@ public class PeerConnectivityManager {
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 @@ public class PeerConnectivityManager {
}
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 @@ public class PeerConnectivityManager {
TrafficTreatment
treatment
=
DefaultTrafficTreatment
.
builder
()
.
build
();
PointToPointIntent
intent
=
new
PointToPointIntent
(
ne
xtIntentId
()
,
selector
,
treatment
,
bgpdConnectPoint
,
bgpdPeerConnectPoint
);
PointToPointIntent
intent
=
ne
w
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 @@ public class PeerConnectivityManager {
.
matchIPDst
(
IpPrefix
.
valueOf
(
bgpdAddress
.
toInt
(),
IPV4_BIT_LENGTH
))
.
build
();
PointToPointIntent
reversedIntent
=
new
PointToPointIntent
(
ne
xtIntentId
()
,
selector
,
treatment
,
bgpdPeerConnectPoint
,
bgpdConnectPoint
);
PointToPointIntent
reversedIntent
=
ne
w
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
++);
}
}
...
...
apps/sdnip/src/main/java/org/onlab/onos/sdnip/Router.java
View file @
b97cf28
package
org
.
onlab
.
onos
.
sdnip
;
import
java.util.Collection
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.Iterator
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.concurrent.BlockingQueue
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.LinkedBlockingQueue
;
import
java.util.concurrent.Semaphore
;
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
;
...
...
@@ -29,7 +24,6 @@ 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
;
...
...
@@ -42,20 +36,25 @@ 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
;
import
java.util.Collection
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.Iterator
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.concurrent.BlockingQueue
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.LinkedBlockingQueue
;
import
java.util.concurrent.Semaphore
;
/**
* 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 @@ public class Router implements RouteListener {
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 @@ public class Router implements RouteListener {
/**
* 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 @@ public class Router implements RouteListener {
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 @@ public class Router implements RouteListener {
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 @@ public class Router implements RouteListener {
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 @@ public class Router implements RouteListener {
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 @@ public class Router implements RouteListener {
continue
;
}
MultiPointToSinglePointIntent
mp2pIntent
=
(
MultiPointToSinglePointIntent
)
intent
;
(
MultiPointToSinglePointIntent
)
intent
;
/*Match match = mp2pIntent.getMatch();
if (!(match instanceof PacketMatch)) {
continue;
...
...
@@ -309,18 +308,18 @@ public class Router implements RouteListener {
// 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 @@ public class Router implements RouteListener {
// 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 @@ public class Router implements RouteListener {
// 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 @@ public class Router implements RouteListener {
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 @@ public class Router implements RouteListener {
return
;
}
log
.
debug
(
"Intent synchronization: adding Intent for "
+
"prefix: {}"
,
prefix
);
"prefix: {}"
,
prefix
);
intentService
.
submit
(
intent
);
}
if
(!
isElectedLeader
)
{
...
...
@@ -419,8 +418,8 @@ public class Router implements RouteListener {
* 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 @@ public class Router implements RouteListener {
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 @@ public class Router implements RouteListener {
// 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 @@ public class Router implements RouteListener {
* 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 @@ public class Router implements RouteListener {
// 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 @@ public class Router implements RouteListener {
* 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 @@ public class Router implements RouteListener {
// 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 @@ public class Router implements RouteListener {
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 @@ public class Router implements RouteListener {
* 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 class Router implements RouteListener {
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 @@ public class Router implements RouteListener {
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 @@ public class Router implements RouteListener {
}
/**
* 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
{
...
...
apps/sdnip/src/main/java/org/onlab/onos/sdnip/SdnIp.java
View file @
b97cf28
...
...
@@ -10,6 +10,8 @@ import org.apache.felix.scr.annotations.Deactivate;
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 @@ import org.slf4j.Logger;
@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 @@ public class SdnIp implements SdnIpService {
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
);
...
...
apps/sdnip/src/test/java/org/onlab/onos/sdnip/PeerConnectivityManagerTest.java
View file @
b97cf28
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.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.bgp.BgpConstants
;
...
...
@@ -40,13 +27,32 @@ import org.onlab.packet.IpAddress;
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 @@ public class PeerConnectivityManagerTest {
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 @@ public class PeerConnectivityManagerTest {
}
PointToPointIntent
intent
=
new
PointToPointIntent
(
testIntentId
,
builder
.
build
(),
noTreatment
,
APPID
,
builder
.
build
(),
noTreatment
,
srcConnectPoint
,
dstConnectPoint
);
intentList
.
add
(
intent
);
...
...
@@ -429,7 +432,7 @@ public class PeerConnectivityManagerTest {
.
build
();
PointToPointIntent
intent
=
new
PointToPointIntent
(
testIntentId
,
selector
,
noTreatment
,
APPID
,
selector
,
noTreatment
,
srcConnectPoint
,
dstConnectPoint
);
intentList
.
add
(
intent
);
...
...
@@ -511,7 +514,7 @@ public class PeerConnectivityManagerTest {
intentService
=
createMock
(
IntentService
.
class
);
replay
(
intentService
);
peerConnectivityManager
=
new
PeerConnectivityManager
(
configInfoService
,
peerConnectivityManager
=
new
PeerConnectivityManager
(
APPID
,
configInfoService
,
interfaceService
,
intentService
);
}
...
...
@@ -557,7 +560,7 @@ public class PeerConnectivityManagerTest {
providedIntentString
=
providedIntent
.
toString
();
PointToPointIntent
matchIntent
=
new
PointToPointIntent
(
providedIntent
.
i
d
(),
new
PointToPointIntent
(
providedIntent
.
appI
d
(),
intent
.
selector
(),
intent
.
treatment
(),
intent
.
ingressPoint
(),
intent
.
egressPoint
());
...
...
cli/src/main/java/org/onlab/onos/cli/AbstractShellCommand.java
View file @
b97cf28
...
...
@@ -2,6 +2,8 @@ package org.onlab.onos.cli;
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 @@ public abstract class AbstractShellCommand extends OsgiCommandSupport {
}
/**
* 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}
...
...
cli/src/main/java/org/onlab/onos/cli/net/AddHostToHostIntentCommand.java
View file @
b97cf28
...
...
@@ -9,7 +9,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.HostToHostIntent
;
import
org.onlab.onos.net.intent.IntentId
;
import
org.onlab.onos.net.intent.IntentService
;
/**
...
...
@@ -27,8 +26,6 @@ public class AddHostToHostIntentCommand extends AbstractShellCommand {
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 @@ public class AddHostToHostIntentCommand extends AbstractShellCommand {
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
);
}
...
...
cli/src/main/java/org/onlab/onos/cli/net/AddMultiPointToSinglePointIntentCommand.java
View file @
b97cf28
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.DefaultTrafficTreatment;
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 @@ public class AddMultiPointToSinglePointIntentCommand extends AbstractShellComman
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 @@ public class AddMultiPointToSinglePointIntentCommand extends AbstractShellComman
}
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
);
}
...
...
cli/src/main/java/org/onlab/onos/cli/net/AddPointToPointIntentCommand.java
View file @
b97cf28
...
...
@@ -11,11 +11,13 @@ 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.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 @@ public class AddPointToPointIntentCommand extends AbstractShellCommand {
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 @@ public class AddPointToPointIntentCommand extends AbstractShellCommand {
.
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
);
}
...
...
cli/src/main/java/org/onlab/onos/cli/net/IntentPushTestCommand.java
View file @
b97cf28
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.flow.TrafficTreatment;
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 @@ public class IntentPushTestCommand extends AbstractShellCommand
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 @@ public class IntentPushTestCommand extends AbstractShellCommand
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 @@ public class IntentPushTestCommand extends AbstractShellCommand
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
{
...
...
cli/src/main/java/org/onlab/onos/cli/net/IntentRemoveCommand.java
View file @
b97cf28
...
...
@@ -26,9 +26,8 @@ public class IntentRemoveCommand extends AbstractShellCommand {
if
(
radix
==
16
)
{
id
=
id
.
replaceFirst
(
"0x"
,
""
);
}
IntentId
intentId
=
new
IntentId
(
Long
.
parseLong
(
id
,
radix
));
IntentId
intentId
=
IntentId
.
valueOf
(
Long
.
parseLong
(
id
,
radix
));
Intent
intent
=
service
.
getIntent
(
intentId
);
if
(
intent
!=
null
)
{
service
.
withdraw
(
intent
);
...
...
core/api/src/main/java/org/onlab/onos/net/intent/IntentId.java
View file @
b97cf28
...
...
@@ -15,7 +15,7 @@ public final class IntentId implements BatchOperationTarget {
* @param fingerprint long value
* @return intent identifier
*/
static
IntentId
valueOf
(
long
fingerprint
)
{
public
static
IntentId
valueOf
(
long
fingerprint
)
{
return
new
IntentId
(
fingerprint
);
}
...
...
core/net/src/main/java/org/onlab/onos/impl/CoreManager.java
View file @
b97cf28
...
...
@@ -27,6 +27,7 @@ public class CoreManager implements CoreService {
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 @@ public class CoreManager implements CoreService {
@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
;
}
...
...
core/net/src/main/java/org/onlab/onos/net/intent/impl/HostToHostIntentCompiler.java
View file @
b97cf28
...
...
@@ -11,11 +11,9 @@ import org.onlab.onos.net.Path;
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 @@ public class HostToHostIntentCompiler
@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 @@ public class HostToHostIntentCompiler
// 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
)
{
...
...
core/net/src/main/java/org/onlab/onos/net/intent/impl/IdBlockAllocatorBasedIntentIdGenerator.java
deleted
100644 → 0
View file @
1c184f1
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
);
}
}
core/net/src/main/java/org/onlab/onos/net/intent/impl/IntentManager.java
View file @
b97cf28
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.event.EventDeliveryService;
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.IntentStore;
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 @@ public class IntentManager
// 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
In
stallableIn
tent
>,
IntentInstaller
<?
extends
In
stallableIn
tent
>>
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 @@ public class IntentManager
}
@Override
public
<
T
extends
In
stallableIn
tent
>
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
In
stallableIn
tent
>
void
unregisterInstaller
(
Class
<
T
>
cls
)
{
public
<
T
extends
Intent
>
void
unregisterInstaller
(
Class
<
T
>
cls
)
{
installers
.
remove
(
cls
);
}
@Override
public
Map
<
Class
<?
extends
In
stallableIntent
>,
IntentInstaller
<?
extends
Installable
Intent
>>
getInstallers
()
{
public
Map
<
Class
<?
extends
In
tent
>,
IntentInstaller
<?
extends
Intent
>>
getInstallers
()
{
return
ImmutableMap
.
copyOf
(
installers
);
}
...
...
@@ -223,7 +215,7 @@ public class IntentManager
* @param <T> the type of installable intent
* @return intent installer corresponding to the specified installable intent
*/
private
<
T
extends
In
stallableIn
tent
>
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 @@ public class IntentManager
try
{
// Compile the intent into installable derivatives.
List
<
In
stallableIn
tent
>
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 @@ public class IntentManager
* @param intent intent
* @return result of compilation
*/
private
List
<
In
stallableIn
tent
>
compileIntent
(
Intent
intent
)
{
if
(
intent
instanceof
In
stallableIn
tent
)
{
return
ImmutableList
.
of
((
In
stallableIn
tent
)
intent
);
private
List
<
Intent
>
compileIntent
(
Intent
intent
)
{
if
(
intent
instanceof
Intent
)
{
return
ImmutableList
.
of
((
Intent
)
intent
);
}
List
<
In
stallableIn
tent
>
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 @@ public class IntentManager
List
<
FlowRuleBatchOperation
>
installWork
=
Lists
.
newArrayList
();
try
{
List
<
In
stallableIn
tent
>
installables
=
store
.
getInstallableIntents
(
intent
.
id
());
List
<
Intent
>
installables
=
store
.
getInstallableIntents
(
intent
.
id
());
if
(
installables
!=
null
)
{
for
(
In
stallableIn
tent
installable
:
installables
)
{
for
(
Intent
installable
:
installables
)
{
registerSubclassInstallerIfNeeded
(
installable
);
trackerService
.
addTrackedResources
(
intent
.
id
(),
installable
.
re
quiredLink
s
());
installable
.
re
source
s
());
List
<
FlowRuleBatchOperation
>
batch
=
getInstaller
(
installable
).
install
(
installable
);
installWork
.
addAll
(
batch
);
}
...
...
@@ -324,14 +316,13 @@ public class IntentManager
try
{
// Compile the intent into installable derivatives.
List
<
In
stallableIn
tent
>
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 @@ public class IntentManager
private
void
uninstallIntent
(
Intent
intent
,
IntentState
nextState
)
{
List
<
FlowRuleBatchOperation
>
uninstallWork
=
Lists
.
newArrayList
();
try
{
List
<
In
stallableIn
tent
>
installables
=
store
.
getInstallableIntents
(
intent
.
id
());
List
<
Intent
>
installables
=
store
.
getInstallableIntents
(
intent
.
id
());
if
(
installables
!=
null
)
{
for
(
In
stallableIn
tent
installable
:
installables
)
{
for
(
Intent
installable
:
installables
)
{
List
<
FlowRuleBatchOperation
>
batches
=
getInstaller
(
installable
).
uninstall
(
installable
);
uninstallWork
.
addAll
(
batches
);
}
...
...
@@ -422,12 +413,12 @@ public class IntentManager
*
* @param intent intent
*/
private
void
registerSubclassInstallerIfNeeded
(
In
stallableIn
tent
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 In
stallableIn
tent class descendants
if
(
In
stallableIn
tent
.
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 @@ public class IntentManager
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 @@ public class IntentManager
}
/**
* Apply a list of FlowRules.
*
* @param rules rules to apply
* Applies the next batch.
*/
private
Future
<
CompletedBatchOperation
>
applyNextBatch
()
{
if
(
work
.
isEmpty
())
{
...
...
core/net/src/main/java/org/onlab/onos/net/intent/impl/MultiPointToSinglePointIntentCompiler.java
View file @
b97cf28
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.apache.felix.scr.annotations.ReferenceCardinality;
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 @@ public class MultiPointToSinglePointIntentCompiler
@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 @@ public class MultiPointToSinglePointIntentCompiler
links
.
addAll
(
path
.
links
());
}
Intent
result
=
new
LinkCollectionIntent
(
intent
IdGenerator
.
getNew
Id
(),
intent
.
selector
(),
intent
.
treatment
(),
links
,
intent
.
egressPoint
());
Intent
result
=
new
LinkCollectionIntent
(
intent
.
app
Id
(),
intent
.
selector
(),
intent
.
treatment
(),
links
,
intent
.
egressPoint
());
return
Arrays
.
asList
(
result
);
}
...
...
core/net/src/main/java/org/onlab/onos/net/intent/impl/ObjectiveTracker.java
View file @
b97cf28
...
...
@@ -11,6 +11,7 @@ import org.apache.felix.scr.annotations.Service;
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.checkArgument;
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 @@ public class ObjectiveTracker implements ObjectiveTrackerService {
}
@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
);
}
}
}
...
...
core/net/src/main/java/org/onlab/onos/net/intent/impl/ObjectiveTrackerService.java
View file @
b97cf28
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 @@ public interface ObjectiveTrackerService {
/**
* 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
);
}
...
...
core/net/src/main/java/org/onlab/onos/net/intent/impl/PointToPointIntentCompiler.java
View file @
b97cf28
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.DefaultPath;
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 @@ public class PointToPointIntentCompiler
@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 @@ public class PointToPointIntentCompiler
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
);
}
/**
...
...
core/net/src/test/java/org/onlab/onos/net/intent/TestHostToHostIntent.java
View file @
b97cf28
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 @@ import static org.onlab.onos.net.NetTestTools.hid;
*/
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 @@ public class TestHostToHostIntent {
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
)));
}
...
...
@@ -51,23 +51,8 @@ public class TestHostToHostIntent {
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
);
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
);
HostToHostIntent
i1
=
makeHostToHost
(
one
,
two
);
HostToHostIntent
i2
=
makeHostToHost
(
two
,
one
);
assertThat
(
i1
,
is
(
not
(
equalTo
(
i2
))));
}
...
...
@@ -76,13 +61,12 @@ public class TestHostToHostIntent {
* 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 +75,12 @@ public class TestHostToHostIntent {
* 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
);
HostToHostIntent
i1
=
makeHostToHost
(
one
,
two
);
HostToHostIntent
i2
=
makeHostToHost
(
two
,
one
);
assertThat
(
i1
.
hashCode
(),
is
(
not
(
equalTo
(
i2
.
hashCode
()))));
}
...
...
core/net/src/test/java/org/onlab/onos/net/intent/TestLinkCollectionIntent.java
View file @
b97cf28
...
...
@@ -11,6 +11,8 @@ 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.DeviceId
;
import
org.onlab.onos.net.Link
;
...
...
@@ -23,6 +25,8 @@ import org.onlab.onos.net.flow.TrafficTreatment;
*/
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 @@ public class TestLinkCollectionIntent {
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 @@ public class TestLinkCollectionIntent {
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 @@ public class TestLinkCollectionIntent {
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 @@ public class TestLinkCollectionIntent {
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 @@ public class TestLinkCollectionIntent {
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 @@ public class TestLinkCollectionIntent {
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
()))));
}
...
...
core/net/src/test/java/org/onlab/onos/net/intent/TestMultiPointToSinglePointIntent.java
View file @
b97cf28
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 @@ import static org.onlab.onos.net.NetTestTools.connectPoint;
*/
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 @@ public class TestMultiPointToSinglePointIntent {
/**
* 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 @@ public class TestMultiPointToSinglePointIntent {
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 @@ public class TestMultiPointToSinglePointIntent {
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 @@ public class TestMultiPointToSinglePointIntent {
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 @@ public class TestMultiPointToSinglePointIntent {
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
()))));
...
...
core/net/src/test/java/org/onlab/onos/net/intent/TestPointToPointIntent.java
View file @
b97cf28
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 @@ import static org.onlab.onos.net.NetTestTools.connectPoint;
*/
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 @@ public class TestPointToPointIntent {
*/
@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 @@ public class TestPointToPointIntent {
*/
@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 @@ public class TestPointToPointIntent {
*/
@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 @@ public class TestPointToPointIntent {
*/
@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
()))));
}
...
...
core/net/src/test/java/org/onlab/onos/net/intent/impl/TestHostToHostIntentCompiler.java
View file @
b97cf28
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.flow.TrafficTreatment;
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 @@ public class TestHostToHostIntentCompiler {
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 @@ public class TestHostToHostIntentCompiler {
* @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 @@ public class TestHostToHostIntentCompiler {
new
HostToHostIntentCompiler
();
compiler
.
pathService
=
new
IntentTestsMocks
.
MockPathService
(
hops
);
compiler
.
hostService
=
mockHostService
;
IdBlockAllocator
idBlockAllocator
=
new
DummyIdBlockAllocator
();
compiler
.
intentIdGenerator
=
new
IdBlockAllocatorBasedIntentIdGenerator
(
idBlockAllocator
);
return
compiler
;
}
...
...
core/net/src/test/java/org/onlab/onos/net/intent/impl/TestMultiPointToSinglePointIntentCompiler.java
View file @
b97cf28
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 @@ import static org.onlab.onos.net.intent.LinksHaveEntryWithSourceDestinationPairM
*/
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 @@ public class TestMultiPointToSinglePointIntentCompiler {
* 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 @@ public class TestMultiPointToSinglePointIntentCompiler {
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 @@ public class TestMultiPointToSinglePointIntentCompiler {
MultiPointToSinglePointIntentCompiler
compiler
=
new
MultiPointToSinglePointIntentCompiler
();
compiler
.
pathService
=
new
MockPathService
(
hops
);
IdBlockAllocator
idBlockAllocator
=
new
DummyIdBlockAllocator
();
compiler
.
intentIdGenerator
=
new
IdBlockAllocatorBasedIntentIdGenerator
(
idBlockAllocator
);
return
compiler
;
}
...
...
@@ -122,7 +118,7 @@ public class TestMultiPointToSinglePointIntentCompiler {
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 @@ public class TestMultiPointToSinglePointIntentCompiler {
@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
);
...
...
core/net/src/test/java/org/onlab/onos/net/intent/impl/TestPointToPointIntentCompiler.java
View file @
b97cf28
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 @@ import static org.onlab.onos.net.intent.LinksHaveEntryWithSourceDestinationPairM
*/
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 @@ public class TestPointToPointIntentCompiler {
* 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 @@ public class TestPointToPointIntentCompiler {
PointToPointIntentCompiler
compiler
=
new
PointToPointIntentCompiler
();
compiler
.
pathService
=
new
IntentTestsMocks
.
MockPathService
(
hops
);
IdBlockAllocator
idBlockAllocator
=
new
DummyIdBlockAllocator
();
compiler
.
intentIdGenerator
=
new
IdBlockAllocatorBasedIntentIdGenerator
(
idBlockAllocator
);
return
compiler
;
}
...
...
core/store/dist/src/main/java/org/onlab/onos/store/intent/impl/DistributedIntentStore.java
View file @
b97cf28
package
org
.
onlab
.
onos
.
store
.
intent
.
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.net.intent.IntentStoreDelegate;
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
;
//FIXME: I LIE I AM NOT DISTRIBUTED
@Component
(
immediate
=
true
)
...
...
@@ -36,8 +31,7 @@ public class DistributedIntentStore
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
=
new
ConcurrentHashMap
<>();
private
final
Map
<
IntentId
,
List
<
Intent
>>
installable
=
new
ConcurrentHashMap
<>();
@Activate
public
void
activate
()
{
...
...
@@ -97,12 +91,12 @@ public class DistributedIntentStore
}
@Override
public
void
addInstallableIntents
(
IntentId
intentId
,
List
<
In
stallableIn
tent
>
result
)
{
public
void
addInstallableIntents
(
IntentId
intentId
,
List
<
Intent
>
result
)
{
installable
.
put
(
intentId
,
result
);
}
@Override
public
List
<
In
stallableIn
tent
>
getInstallableIntents
(
IntentId
intentId
)
{
public
List
<
Intent
>
getInstallableIntents
(
IntentId
intentId
)
{
return
installable
.
get
(
intentId
);
}
...
...
Please
register
or
login
to post a comment