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-24 09:22:02 -0700
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
1380eee1aa12b82f5fca868d5a428858f27b7d09
1380eee1
1 parent
b41d1aca
Cleaned-up CLI commands.
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
170 additions
and
85 deletions
cli/src/main/java/org/onlab/onos/cli/MastersListCommand.java
cli/src/main/java/org/onlab/onos/cli/NodeIdCompleter.java
cli/src/main/java/org/onlab/onos/cli/NodesListCommand.java
cli/src/main/java/org/onlab/onos/cli/net/ClusterDevicesCommand.java
cli/src/main/java/org/onlab/onos/cli/net/ClustersListCommand.java
cli/src/main/java/org/onlab/onos/cli/net/Comparators.java
cli/src/main/java/org/onlab/onos/cli/net/DevicePortsListCommand.java
cli/src/main/java/org/onlab/onos/cli/net/DevicesListCommand.java
cli/src/main/java/org/onlab/onos/cli/net/FlowsListCommand.java
cli/src/main/java/org/onlab/onos/cli/net/HostIdCompleter.java
cli/src/main/java/org/onlab/onos/cli/net/HostsListCommand.java
cli/src/main/java/org/onlab/onos/cli/net/LinksListCommand.java
cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
cli/src/main/java/org/onlab/onos/cli/MastersListCommand.java
0 → 100644
View file @
1380eee
package
org
.
onlab
.
onos
.
cli
;
import
com.google.common.collect.Lists
;
import
org.apache.karaf.shell.commands.Command
;
import
org.onlab.onos.cli.net.Comparators
;
import
org.onlab.onos.cluster.ClusterService
;
import
org.onlab.onos.cluster.ControllerNode
;
import
org.onlab.onos.cluster.MastershipService
;
import
org.onlab.onos.net.DeviceId
;
import
java.util.Collections
;
import
java.util.List
;
import
static
com
.
google
.
common
.
collect
.
Lists
.
newArrayList
;
/**
* Lists device mastership information.
*/
@Command
(
scope
=
"onos"
,
name
=
"masters"
,
description
=
"Lists device mastership information"
)
public
class
MastersListCommand
extends
AbstractShellCommand
{
@Override
protected
void
execute
()
{
ClusterService
service
=
get
(
ClusterService
.
class
);
MastershipService
mastershipService
=
get
(
MastershipService
.
class
);
List
<
ControllerNode
>
nodes
=
newArrayList
(
service
.
getNodes
());
Collections
.
sort
(
nodes
,
Comparators
.
NODE_COMPARATOR
);
ControllerNode
self
=
service
.
getLocalNode
();
for
(
ControllerNode
node
:
nodes
)
{
List
<
DeviceId
>
ids
=
Lists
.
newArrayList
(
mastershipService
.
getDevicesOf
(
node
.
id
()));
Collections
.
sort
(
ids
,
Comparators
.
ELEMENT_ID_COMPARATOR
);
print
(
"%s: %d devices"
,
node
.
id
(),
ids
.
size
());
for
(
DeviceId
deviceId
:
ids
)
{
print
(
" %s"
,
deviceId
);
}
}
}
}
cli/src/main/java/org/onlab/onos/cli/NodeIdCompleter.java
0 → 100644
View file @
1380eee
package
org
.
onlab
.
onos
.
cli
;
import
org.apache.karaf.shell.console.Completer
;
import
org.apache.karaf.shell.console.completer.StringsCompleter
;
import
org.onlab.onos.cluster.ClusterService
;
import
org.onlab.onos.cluster.ControllerNode
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.SortedSet
;
/**
* Node ID completer.
*/
public
class
NodeIdCompleter
implements
Completer
{
@Override
public
int
complete
(
String
buffer
,
int
cursor
,
List
<
String
>
candidates
)
{
// Delegate string completer
StringsCompleter
delegate
=
new
StringsCompleter
();
// Fetch our service and feed it's offerings to the string completer
ClusterService
service
=
AbstractShellCommand
.
get
(
ClusterService
.
class
);
Iterator
<
ControllerNode
>
it
=
service
.
getNodes
().
iterator
();
SortedSet
<
String
>
strings
=
delegate
.
getStrings
();
while
(
it
.
hasNext
())
{
strings
.
add
(
it
.
next
().
id
().
toString
());
}
// Now let the completer do the work for figuring out what to offer.
return
delegate
.
complete
(
buffer
,
cursor
,
candidates
);
}
}
cli/src/main/java/org/onlab/onos/cli/NodesListCommand.java
View file @
1380eee
package
org
.
onlab
.
onos
.
cli
;
import
org.apache.karaf.shell.commands.Command
;
import
org.onlab.onos.cli.net.Comparators
;
import
org.onlab.onos.cluster.ClusterService
;
import
org.onlab.onos.cluster.ControllerNode
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.List
;
import
static
com
.
google
.
common
.
collect
.
Lists
.
newArrayList
;
...
...
@@ -20,19 +20,11 @@ public class NodesListCommand extends AbstractShellCommand {
private
static
final
String
FMT
=
"id=%s, ip=%s, state=%s %s"
;
protected
static
final
Comparator
<
ControllerNode
>
ID_COMPARATOR
=
new
Comparator
<
ControllerNode
>()
{
@Override
public
int
compare
(
ControllerNode
ci1
,
ControllerNode
ci2
)
{
return
ci1
.
id
().
toString
().
compareTo
(
ci2
.
id
().
toString
());
}
};
@Override
protected
void
execute
()
{
ClusterService
service
=
get
(
ClusterService
.
class
);
List
<
ControllerNode
>
nodes
=
newArrayList
(
service
.
getNodes
());
Collections
.
sort
(
nodes
,
ID
_COMPARATOR
);
Collections
.
sort
(
nodes
,
Comparators
.
NODE
_COMPARATOR
);
ControllerNode
self
=
service
.
getLocalNode
();
for
(
ControllerNode
node
:
nodes
)
{
print
(
FMT
,
node
.
id
(),
node
.
ip
(),
...
...
cli/src/main/java/org/onlab/onos/cli/net/ClusterDevicesCommand.java
View file @
1380eee
...
...
@@ -7,7 +7,6 @@ import org.onlab.onos.net.DeviceId;
import
org.onlab.onos.net.topology.TopologyCluster
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.List
;
import
static
org
.
onlab
.
onos
.
net
.
topology
.
ClusterId
.
clusterId
;
...
...
@@ -23,13 +22,6 @@ public class ClusterDevicesCommand extends ClustersListCommand {
required
=
false
,
multiValued
=
false
)
String
id
=
null
;
protected
static
final
Comparator
<
DeviceId
>
ID_COMPARATOR
=
new
Comparator
<
DeviceId
>()
{
@Override
public
int
compare
(
DeviceId
id1
,
DeviceId
id2
)
{
return
id1
.
uri
().
toString
().
compareTo
(
id2
.
uri
().
toString
());
}
};
@Override
protected
void
execute
()
{
int
cid
=
Integer
.
parseInt
(
id
);
...
...
@@ -39,7 +31,7 @@ public class ClusterDevicesCommand extends ClustersListCommand {
error
(
"No such cluster %s"
,
cid
);
}
else
{
List
<
DeviceId
>
ids
=
Lists
.
newArrayList
(
service
.
getClusterDevices
(
topology
,
cluster
));
Collections
.
sort
(
ids
,
ID_COMPARATOR
);
Collections
.
sort
(
ids
,
Comparators
.
ELEMENT_
ID_COMPARATOR
);
for
(
DeviceId
deviceId
:
ids
)
{
print
(
"%s"
,
deviceId
);
}
...
...
cli/src/main/java/org/onlab/onos/cli/net/ClustersListCommand.java
View file @
1380eee
...
...
@@ -5,7 +5,6 @@ import org.apache.karaf.shell.commands.Command;
import
org.onlab.onos.net.topology.TopologyCluster
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.List
;
/**
...
...
@@ -18,19 +17,11 @@ public class ClustersListCommand extends TopologyCommand {
private
static
final
String
FMT
=
"id=%d, devices=%d, links=%d"
;
protected
static
final
Comparator
<
TopologyCluster
>
ID_COMPARATOR
=
new
Comparator
<
TopologyCluster
>()
{
@Override
public
int
compare
(
TopologyCluster
c1
,
TopologyCluster
c2
)
{
return
c1
.
id
().
index
()
-
c2
.
id
().
index
();
}
};
@Override
protected
void
execute
()
{
init
();
List
<
TopologyCluster
>
clusters
=
Lists
.
newArrayList
(
service
.
getClusters
(
topology
));
Collections
.
sort
(
clusters
,
ID
_COMPARATOR
);
Collections
.
sort
(
clusters
,
Comparators
.
CLUSTER
_COMPARATOR
);
for
(
TopologyCluster
cluster
:
clusters
)
{
print
(
FMT
,
cluster
.
id
().
index
(),
cluster
.
deviceCount
(),
cluster
.
linkCount
());
...
...
cli/src/main/java/org/onlab/onos/cli/net/Comparators.java
0 → 100644
View file @
1380eee
package
org
.
onlab
.
onos
.
cli
.
net
;
import
org.onlab.onos.cluster.ControllerNode
;
import
org.onlab.onos.net.Element
;
import
org.onlab.onos.net.ElementId
;
import
org.onlab.onos.net.Port
;
import
org.onlab.onos.net.flow.FlowRule
;
import
org.onlab.onos.net.topology.TopologyCluster
;
import
java.util.Comparator
;
/**
* Various comparators.
*/
public
final
class
Comparators
{
// Ban construction
private
Comparators
()
{
}
public
static
final
Comparator
<
ElementId
>
ELEMENT_ID_COMPARATOR
=
new
Comparator
<
ElementId
>()
{
@Override
public
int
compare
(
ElementId
id1
,
ElementId
id2
)
{
return
id1
.
uri
().
toString
().
compareTo
(
id2
.
uri
().
toString
());
}
};
public
static
final
Comparator
<
Element
>
ELEMENT_COMPARATOR
=
new
Comparator
<
Element
>()
{
@Override
public
int
compare
(
Element
e1
,
Element
e2
)
{
return
e1
.
id
().
uri
().
toString
().
compareTo
(
e2
.
id
().
uri
().
toString
());
}
};
public
static
final
Comparator
<
FlowRule
>
FLOW_RULE_COMPARATOR
=
new
Comparator
<
FlowRule
>()
{
@Override
public
int
compare
(
FlowRule
f1
,
FlowRule
f2
)
{
return
Long
.
valueOf
(
f1
.
id
().
value
()).
compareTo
(
f2
.
id
().
value
());
}
};
public
static
final
Comparator
<
Port
>
PORT_COMPARATOR
=
new
Comparator
<
Port
>()
{
@Override
public
int
compare
(
Port
p1
,
Port
p2
)
{
long
delta
=
p1
.
number
().
toLong
()
-
p2
.
number
().
toLong
();
return
delta
==
0
?
0
:
(
delta
<
0
?
-
1
:
+
1
);
}
};
public
static
final
Comparator
<
TopologyCluster
>
CLUSTER_COMPARATOR
=
new
Comparator
<
TopologyCluster
>()
{
@Override
public
int
compare
(
TopologyCluster
c1
,
TopologyCluster
c2
)
{
return
c1
.
id
().
index
()
-
c2
.
id
().
index
();
}
};
public
static
final
Comparator
<
ControllerNode
>
NODE_COMPARATOR
=
new
Comparator
<
ControllerNode
>()
{
@Override
public
int
compare
(
ControllerNode
ci1
,
ControllerNode
ci2
)
{
return
ci1
.
id
().
toString
().
compareTo
(
ci2
.
id
().
toString
());
}
};
}
cli/src/main/java/org/onlab/onos/cli/net/DevicePortsListCommand.java
View file @
1380eee
...
...
@@ -8,7 +8,6 @@ import org.onlab.onos.net.device.DeviceService;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.List
;
import
static
org
.
onlab
.
onos
.
net
.
DeviceId
.
deviceId
;
...
...
@@ -26,14 +25,6 @@ public class DevicePortsListCommand extends DevicesListCommand {
required
=
false
,
multiValued
=
false
)
String
uri
=
null
;
private
static
final
Comparator
<
Port
>
PORT_COMPARATOR
=
new
Comparator
<
Port
>()
{
@Override
public
int
compare
(
Port
p1
,
Port
p2
)
{
long
delta
=
p1
.
number
().
toLong
()
-
p2
.
number
().
toLong
();
return
delta
==
0
?
0
:
(
delta
<
0
?
-
1
:
+
1
);
}
};
@Override
protected
void
execute
()
{
DeviceService
service
=
get
(
DeviceService
.
class
);
...
...
@@ -55,7 +46,7 @@ public class DevicePortsListCommand extends DevicesListCommand {
protected
void
printDevice
(
DeviceService
service
,
Device
device
)
{
super
.
printDevice
(
service
,
device
);
List
<
Port
>
ports
=
new
ArrayList
<>(
service
.
getPorts
(
device
.
id
()));
Collections
.
sort
(
ports
,
PORT_COMPARATOR
);
Collections
.
sort
(
ports
,
Comparators
.
PORT_COMPARATOR
);
for
(
Port
port
:
ports
)
{
print
(
FMT
,
port
.
number
(),
port
.
isEnabled
()
?
"enabled"
:
"disabled"
);
}
...
...
cli/src/main/java/org/onlab/onos/cli/net/DevicesListCommand.java
View file @
1380eee
...
...
@@ -6,7 +6,6 @@ import org.onlab.onos.net.Device;
import
org.onlab.onos.net.device.DeviceService
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.List
;
import
static
com
.
google
.
common
.
collect
.
Lists
.
newArrayList
;
...
...
@@ -21,13 +20,6 @@ public class DevicesListCommand extends AbstractShellCommand {
private
static
final
String
FMT
=
"id=%s, available=%s, role=%s, type=%s, mfr=%s, hw=%s, sw=%s, serial=%s"
;
protected
static
final
Comparator
<
Device
>
ID_COMPARATOR
=
new
Comparator
<
Device
>()
{
@Override
public
int
compare
(
Device
d1
,
Device
d2
)
{
return
d1
.
id
().
uri
().
toString
().
compareTo
(
d2
.
id
().
uri
().
toString
());
}
};
@Override
protected
void
execute
()
{
DeviceService
service
=
get
(
DeviceService
.
class
);
...
...
@@ -44,7 +36,7 @@ public class DevicesListCommand extends AbstractShellCommand {
*/
protected
List
<
Device
>
getSortedDevices
(
DeviceService
service
)
{
List
<
Device
>
devices
=
newArrayList
(
service
.
getDevices
());
Collections
.
sort
(
devices
,
ID
_COMPARATOR
);
Collections
.
sort
(
devices
,
Comparators
.
ELEMENT
_COMPARATOR
);
return
devices
;
}
...
...
cli/src/main/java/org/onlab/onos/cli/net/FlowsListCommand.java
View file @
1380eee
package
org
.
onlab
.
onos
.
cli
.
net
;
import
static
com
.
google
.
common
.
collect
.
Lists
.
newArrayList
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.List
;
import
java.util.Map
;
import
com.google.common.collect.Maps
;
import
org.apache.karaf.shell.commands.Command
;
import
org.onlab.onos.cli.AbstractShellCommand
;
import
org.onlab.onos.net.Device
;
...
...
@@ -14,7 +8,11 @@ import org.onlab.onos.net.device.DeviceService;
import
org.onlab.onos.net.flow.FlowRule
;
import
org.onlab.onos.net.flow.FlowRuleService
;
import
com.google.common.collect.Maps
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Map
;
import
static
com
.
google
.
common
.
collect
.
Lists
.
newArrayList
;
/**
* Lists all currently-known hosts.
...
...
@@ -26,13 +24,6 @@ public class FlowsListCommand extends AbstractShellCommand {
private
static
final
String
FMT
=
" id=%s, selector=%s, treatment=%s, state=%s"
;
protected
static
final
Comparator
<
FlowRule
>
ID_COMPARATOR
=
new
Comparator
<
FlowRule
>()
{
@Override
public
int
compare
(
FlowRule
f1
,
FlowRule
f2
)
{
return
Long
.
valueOf
(
f1
.
id
().
value
()).
compareTo
(
f2
.
id
().
value
());
}
};
@Override
protected
void
execute
()
{
DeviceService
deviceService
=
get
(
DeviceService
.
class
);
...
...
@@ -43,7 +34,6 @@ public class FlowsListCommand extends AbstractShellCommand {
}
}
/**
* Returns the list of devices sorted using the device ID URIs.
*
...
...
@@ -55,7 +45,7 @@ public class FlowsListCommand extends AbstractShellCommand {
List
<
FlowRule
>
rules
;
for
(
Device
d
:
deviceService
.
getDevices
())
{
rules
=
newArrayList
(
service
.
getFlowEntries
(
d
.
id
()));
Collections
.
sort
(
rules
,
ID
_COMPARATOR
);
Collections
.
sort
(
rules
,
Comparators
.
FLOW_RULE
_COMPARATOR
);
flows
.
put
(
d
,
rules
);
}
return
flows
;
...
...
cli/src/main/java/org/onlab/onos/cli/net/HostIdCompleter.java
View file @
1380eee
package
org
.
onlab
.
onos
.
cli
.
net
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.SortedSet
;
import
org.apache.karaf.shell.console.Completer
;
import
org.apache.karaf.shell.console.completer.StringsCompleter
;
import
org.onlab.onos.cli.AbstractShellCommand
;
import
org.onlab.onos.net.Host
;
import
org.onlab.onos.net.host.HostService
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.SortedSet
;
public
class
HostIdCompleter
implements
Completer
{
@Override
...
...
cli/src/main/java/org/onlab/onos/cli/net/HostsListCommand.java
View file @
1380eee
package
org
.
onlab
.
onos
.
cli
.
net
;
import
static
com
.
google
.
common
.
collect
.
Lists
.
newArrayList
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.List
;
import
org.apache.karaf.shell.commands.Command
;
import
org.onlab.onos.cli.AbstractShellCommand
;
import
org.onlab.onos.net.Host
;
import
org.onlab.onos.net.host.HostService
;
import
java.util.Collections
;
import
java.util.List
;
import
static
com
.
google
.
common
.
collect
.
Lists
.
newArrayList
;
/**
* Lists all currently-known hosts.
*/
...
...
@@ -21,13 +20,6 @@ public class HostsListCommand extends AbstractShellCommand {
private
static
final
String
FMT
=
"id=%s, mac=%s, location=%s/%s, vlan=%s, ip(s)=%s"
;
protected
static
final
Comparator
<
Host
>
ID_COMPARATOR
=
new
Comparator
<
Host
>()
{
@Override
public
int
compare
(
Host
h1
,
Host
h2
)
{
return
h1
.
id
().
uri
().
toString
().
compareTo
(
h2
.
id
().
uri
().
toString
());
}
};
@Override
protected
void
execute
()
{
HostService
service
=
get
(
HostService
.
class
);
...
...
@@ -44,7 +36,7 @@ public class HostsListCommand extends AbstractShellCommand {
*/
protected
List
<
Host
>
getSortedHosts
(
HostService
service
)
{
List
<
Host
>
hosts
=
newArrayList
(
service
.
getHosts
());
Collections
.
sort
(
hosts
,
ID
_COMPARATOR
);
Collections
.
sort
(
hosts
,
Comparators
.
ELEMENT
_COMPARATOR
);
return
hosts
;
}
...
...
cli/src/main/java/org/onlab/onos/cli/net/LinksListCommand.java
View file @
1380eee
...
...
@@ -41,7 +41,6 @@ public class LinksListCommand extends AbstractShellCommand {
public
static
String
linkString
(
Link
link
)
{
return
String
.
format
(
FMT
,
link
.
src
().
deviceId
(),
link
.
src
().
port
(),
link
.
dst
().
deviceId
(),
link
.
dst
().
port
(),
link
.
type
());
}
/**
...
...
cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
View file @
1380eee
...
...
@@ -5,8 +5,12 @@
<action
class=
"org.onlab.onos.cli.NodesListCommand"
/>
</command>
<command>
<action
class=
"org.onlab.onos.cli.net.FlowsListCommand"
/>
<action
class=
"org.onlab.onos.cli.MastersListCommand"
/>
<completers>
<ref
component-id=
"clusterIdCompleter"
/>
</completers>
</command>
<command>
<action
class=
"org.onlab.onos.cli.net.DevicesListCommand"
/>
</command>
...
...
@@ -67,10 +71,15 @@
</command>
<command>
<action
class=
"org.onlab.onos.cli.net.FlowsListCommand"
/>
</command>
<command>
<action
class=
"org.onlab.onos.cli.net.WipeOutCommand"
/>
</command>
</command-bundle>
<bean
id=
"nodeIdCompleter"
class=
"org.onlab.onos.cli.NodeIdCompleter"
/>
<bean
id=
"deviceIdCompleter"
class=
"org.onlab.onos.cli.net.DeviceIdCompleter"
/>
<bean
id=
"clusterIdCompleter"
class=
"org.onlab.onos.cli.net.ClusterIdCompleter"
/>
<bean
id=
"roleCompleter"
class=
"org.onlab.onos.cli.net.RoleCompleter"
/>
...
...
Please
register
or
login
to post a comment