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
tom
2014-09-14 23:12:28 -0700
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
4d0dd3a33721f645e0a7eef47f6aef16780e1173
4d0dd3a3
1 parent
16698a3f
Adding topology test suite.
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
237 additions
and
9 deletions
core/api/src/main/java/org/onlab/onos/net/topology/TopologyService.java
core/trivial/src/main/java/org/onlab/onos/net/trivial/topology/impl/SimpleTopologyManager.java
core/trivial/src/main/java/org/onlab/onos/net/trivial/topology/impl/SimpleTopologyStore.java
core/trivial/src/test/java/org/onlab/onos/net/trivial/topology/impl/SimpleTopologyManagerTest.java
core/api/src/main/java/org/onlab/onos/net/topology/TopologyService.java
View file @
4d0dd3a
...
...
@@ -105,14 +105,14 @@ public interface TopologyService {
/**
* Indicates whether
the specified connection point belong to
the
*
broadcast tree
.
* Indicates whether
broadcast is allowed for traffic received on
the
*
specified connection point
.
*
* @param topology topology descriptor
* @param connectPoint connection point
* @return true if broadcast is permissible
*/
boolean
is
InBroadcastTree
(
Topology
topology
,
ConnectPoint
connectPoint
);
boolean
is
BroadcastPoint
(
Topology
topology
,
ConnectPoint
connectPoint
);
/**
* Adds the specified topology listener.
...
...
core/trivial/src/main/java/org/onlab/onos/net/trivial/topology/impl/SimpleTopologyManager.java
View file @
4d0dd3a
...
...
@@ -58,7 +58,7 @@ public class SimpleTopologyManager
private
final
SimpleTopologyStore
store
=
new
SimpleTopologyStore
();
@Reference
(
cardinality
=
ReferenceCardinality
.
MANDATORY_UNARY
)
pr
ivate
EventDeliveryService
eventDispatcher
;
pr
otected
EventDeliveryService
eventDispatcher
;
@Activate
...
...
@@ -151,10 +151,10 @@ public class SimpleTopologyManager
}
@Override
public
boolean
is
InBroadcastTree
(
Topology
topology
,
ConnectPoint
connectPoint
)
{
public
boolean
is
BroadcastPoint
(
Topology
topology
,
ConnectPoint
connectPoint
)
{
checkNotNull
(
topology
,
TOPOLOGY_NULL
);
checkNotNull
(
connectPoint
,
CONNECTION_POINT_NULL
);
return
store
.
is
InBroadcastTree
(
defaultTopology
(
topology
),
connectPoint
);
return
store
.
is
BroadcastPoint
(
defaultTopology
(
topology
),
connectPoint
);
}
@Override
...
...
core/trivial/src/main/java/org/onlab/onos/net/trivial/topology/impl/SimpleTopologyStore.java
View file @
4d0dd3a
...
...
@@ -136,13 +136,14 @@ class SimpleTopologyStore {
}
/**
* Indicates whether the given connect point is part of the broadcast tree.
* Indicates whether broadcast is allowed for traffic received on the
* given connection point.
*
* @param topology topology descriptor
* @param connectPoint connection point
* @return true if
in broadcast tree
; false otherwise
* @return true if
broadcast allowed
; false otherwise
*/
boolean
is
InBroadcastTree
(
DefaultTopology
topology
,
ConnectPoint
connectPoint
)
{
boolean
is
BroadcastPoint
(
DefaultTopology
topology
,
ConnectPoint
connectPoint
)
{
return
topology
.
isInBroadcastTree
(
connectPoint
);
}
...
...
core/trivial/src/test/java/org/onlab/onos/net/trivial/topology/impl/SimpleTopologyManagerTest.java
0 → 100644
View file @
4d0dd3a
package
org
.
onlab
.
onos
.
net
.
trivial
.
topology
.
impl
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.onlab.onos.event.Event
;
import
org.onlab.onos.event.impl.TestEventDispatcher
;
import
org.onlab.onos.net.ConnectPoint
;
import
org.onlab.onos.net.DefaultDevice
;
import
org.onlab.onos.net.DefaultLink
;
import
org.onlab.onos.net.Device
;
import
org.onlab.onos.net.DeviceId
;
import
org.onlab.onos.net.Link
;
import
org.onlab.onos.net.Path
;
import
org.onlab.onos.net.provider.AbstractProvider
;
import
org.onlab.onos.net.provider.ProviderId
;
import
org.onlab.onos.net.topology.GraphDescription
;
import
org.onlab.onos.net.topology.LinkWeight
;
import
org.onlab.onos.net.topology.Topology
;
import
org.onlab.onos.net.topology.TopologyCluster
;
import
org.onlab.onos.net.topology.TopologyEdge
;
import
org.onlab.onos.net.topology.TopologyEvent
;
import
org.onlab.onos.net.topology.TopologyGraph
;
import
org.onlab.onos.net.topology.TopologyListener
;
import
org.onlab.onos.net.topology.TopologyProvider
;
import
org.onlab.onos.net.topology.TopologyProviderRegistry
;
import
org.onlab.onos.net.topology.TopologyProviderService
;
import
org.onlab.onos.net.topology.TopologyService
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Set
;
import
static
com
.
google
.
common
.
collect
.
ImmutableSet
.
of
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
onlab
.
onos
.
net
.
DeviceId
.
deviceId
;
import
static
org
.
onlab
.
onos
.
net
.
PortNumber
.
portNumber
;
import
static
org
.
onlab
.
onos
.
net
.
topology
.
ClusterId
.
clusterId
;
import
static
org
.
onlab
.
onos
.
net
.
topology
.
TopologyEvent
.
Type
.
TOPOLOGY_CHANGED
;
/**
* Test of the topology subsystem.
*/
public
class
SimpleTopologyManagerTest
{
private
static
final
ProviderId
PID
=
new
ProviderId
(
"foo"
);
private
SimpleTopologyManager
mgr
;
protected
TopologyService
service
;
protected
TopologyProviderRegistry
registry
;
protected
TopologyProviderService
providerService
;
protected
TestProvider
provider
;
protected
TestListener
listener
=
new
TestListener
();
@Before
public
void
setUp
()
{
mgr
=
new
SimpleTopologyManager
();
service
=
mgr
;
registry
=
mgr
;
mgr
.
eventDispatcher
=
new
TestEventDispatcher
();
mgr
.
activate
();
service
.
addListener
(
listener
);
provider
=
new
TestProvider
();
providerService
=
registry
.
register
(
provider
);
assertTrue
(
"provider should be registered"
,
registry
.
getProviders
().
contains
(
provider
.
id
()));
}
@After
public
void
tearDown
()
{
mgr
.
deactivate
();
service
.
removeListener
(
listener
);
}
@Test
public
void
basics
()
{
Topology
topology
=
service
.
currentTopology
();
assertNull
(
"no topo expected"
,
topology
);
submitTopologyGraph
();
validateEvents
(
TOPOLOGY_CHANGED
);
topology
=
service
.
currentTopology
();
assertTrue
(
"should be latest"
,
service
.
isLatest
(
topology
));
submitTopologyGraph
();
validateEvents
(
TOPOLOGY_CHANGED
);
assertFalse
(
"should be latest"
,
service
.
isLatest
(
topology
));
}
private
void
submitTopologyGraph
()
{
Set
<
Device
>
devices
=
of
(
device
(
"a"
),
device
(
"b"
),
device
(
"c"
),
device
(
"d"
),
device
(
"e"
),
device
(
"f"
));
Set
<
Link
>
links
=
of
(
link
(
"a"
,
1
,
"b"
,
1
),
link
(
"b"
,
1
,
"a"
,
1
),
link
(
"b"
,
2
,
"c"
,
1
),
link
(
"c"
,
1
,
"b"
,
2
),
link
(
"c"
,
2
,
"d"
,
1
),
link
(
"d"
,
1
,
"c"
,
2
),
link
(
"d"
,
2
,
"a"
,
2
),
link
(
"a"
,
2
,
"d"
,
2
),
link
(
"e"
,
1
,
"f"
,
1
),
link
(
"f"
,
1
,
"e"
,
1
));
GraphDescription
data
=
new
DefaultGraphDescription
(
4321L
,
devices
,
links
);
providerService
.
topologyChanged
(
data
,
null
);
}
@Test
public
void
clusters
()
{
submitTopologyGraph
();
Topology
topology
=
service
.
currentTopology
();
assertNotNull
(
"topo expected"
,
topology
);
assertEquals
(
"wrong cluster count"
,
2
,
topology
.
clusterCount
());
assertEquals
(
"wrong device count"
,
6
,
topology
.
deviceCount
());
assertEquals
(
"wrong link count"
,
10
,
topology
.
linkCount
());
assertEquals
(
"wrong path count"
,
18
,
topology
.
pathCount
());
assertEquals
(
"wrong cluster count"
,
2
,
service
.
getClusters
(
topology
).
size
());
TopologyCluster
cluster
=
service
.
getCluster
(
topology
,
clusterId
(
0
));
assertEquals
(
"wrong device count"
,
4
,
cluster
.
deviceCount
());
assertEquals
(
"wrong device count"
,
4
,
service
.
getClusterDevices
(
topology
,
cluster
).
size
());
assertEquals
(
"wrong link count"
,
8
,
cluster
.
linkCount
());
assertEquals
(
"wrong link count"
,
8
,
service
.
getClusterLinks
(
topology
,
cluster
).
size
());
}
@Test
public
void
structure
()
{
submitTopologyGraph
();
Topology
topology
=
service
.
currentTopology
();
assertTrue
(
"should be infrastructure point"
,
service
.
isInfrastructure
(
topology
,
new
ConnectPoint
(
did
(
"a"
),
portNumber
(
1
))));
assertFalse
(
"should not be infrastructure point"
,
service
.
isInfrastructure
(
topology
,
new
ConnectPoint
(
did
(
"a"
),
portNumber
(
3
))));
// One of these cannot be a broadcast point... or we have a loop...
assertFalse
(
"should not be broadcast point"
,
service
.
isBroadcastPoint
(
topology
,
new
ConnectPoint
(
did
(
"a"
),
portNumber
(
1
)))
&&
service
.
isBroadcastPoint
(
topology
,
new
ConnectPoint
(
did
(
"b"
),
portNumber
(
1
)))
&&
service
.
isBroadcastPoint
(
topology
,
new
ConnectPoint
(
did
(
"c"
),
portNumber
(
1
)))
&&
service
.
isBroadcastPoint
(
topology
,
new
ConnectPoint
(
did
(
"d"
),
portNumber
(
1
))));
assertTrue
(
"should be broadcast point"
,
service
.
isBroadcastPoint
(
topology
,
new
ConnectPoint
(
did
(
"a"
),
portNumber
(
3
))));
}
@Test
public
void
graph
()
{
submitTopologyGraph
();
Topology
topology
=
service
.
currentTopology
();
TopologyGraph
graph
=
service
.
getGraph
(
topology
);
assertEquals
(
"wrong vertex count"
,
6
,
graph
.
getVertexes
().
size
());
assertEquals
(
"wrong edge count"
,
10
,
graph
.
getEdges
().
size
());
}
@Test
public
void
precomputedPath
()
{
submitTopologyGraph
();
Topology
topology
=
service
.
currentTopology
();
Set
<
Path
>
paths
=
service
.
getPaths
(
topology
,
did
(
"a"
),
did
(
"c"
));
assertEquals
(
"wrong path count"
,
2
,
paths
.
size
());
Path
path
=
paths
.
iterator
().
next
();
assertEquals
(
"wrong path length"
,
2
,
path
.
links
().
size
());
assertEquals
(
"wrong path cost"
,
2
,
path
.
cost
(),
0.01
);
}
@Test
public
void
onDemandPath
()
{
submitTopologyGraph
();
Topology
topology
=
service
.
currentTopology
();
LinkWeight
weight
=
new
LinkWeight
()
{
@Override
public
double
weight
(
TopologyEdge
edge
)
{
return
3.3
;
}
};
Set
<
Path
>
paths
=
service
.
getPaths
(
topology
,
did
(
"a"
),
did
(
"c"
),
weight
);
assertEquals
(
"wrong path count"
,
2
,
paths
.
size
());
Path
path
=
paths
.
iterator
().
next
();
assertEquals
(
"wrong path length"
,
2
,
path
.
links
().
size
());
assertEquals
(
"wrong path cost"
,
6.6
,
path
.
cost
(),
0.01
);
}
// Short-hand for creating a link.
private
Link
link
(
String
src
,
int
sp
,
String
dst
,
int
dp
)
{
return
new
DefaultLink
(
PID
,
new
ConnectPoint
(
did
(
src
),
portNumber
(
sp
)),
new
ConnectPoint
(
did
(
dst
),
portNumber
(
dp
)),
Link
.
Type
.
DIRECT
);
}
// Crates a new device with the specified id
private
Device
device
(
String
id
)
{
return
new
DefaultDevice
(
PID
,
did
(
id
),
Device
.
Type
.
SWITCH
,
"mfg"
,
"1.0"
,
"1.1"
,
"1234"
);
}
// Short-hand for producing a device id from a string
private
DeviceId
did
(
String
id
)
{
return
deviceId
(
"of:"
+
id
);
}
protected
void
validateEvents
(
Enum
...
types
)
{
int
i
=
0
;
assertEquals
(
"wrong events received"
,
types
.
length
,
listener
.
events
.
size
());
for
(
Event
event
:
listener
.
events
)
{
assertEquals
(
"incorrect event type"
,
types
[
i
],
event
.
type
());
i
++;
}
listener
.
events
.
clear
();
}
private
class
TestProvider
extends
AbstractProvider
implements
TopologyProvider
{
public
TestProvider
()
{
super
(
PID
);
}
}
private
static
class
TestListener
implements
TopologyListener
{
final
List
<
TopologyEvent
>
events
=
new
ArrayList
<>();
@Override
public
void
event
(
TopologyEvent
event
)
{
events
.
add
(
event
);
}
}
}
\ No newline at end of file
Please
register
or
login
to post a comment