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-10-16 07:22:02 -0700
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
8350ba5108a478c80f4a1d60ffe35a807e493708
8350ba51
1 parent
a4b548c6
Added option to show only enabled/disabled ports
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
2 deletions
cli/src/main/java/org/onlab/onos/cli/net/DevicePortsListCommand.java
cli/src/main/java/org/onlab/onos/cli/net/DevicePortsListCommand.java
View file @
8350ba5
...
...
@@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
org.apache.karaf.shell.commands.Argument
;
import
org.apache.karaf.shell.commands.Command
;
import
org.apache.karaf.shell.commands.Option
;
import
org.onlab.onos.cli.Comparators
;
import
org.onlab.onos.net.Device
;
import
org.onlab.onos.net.Port
;
...
...
@@ -26,6 +27,14 @@ public class DevicePortsListCommand extends DevicesListCommand {
private
static
final
String
FMT
=
" port=%s, state=%s"
;
@Option
(
name
=
"-e"
,
aliases
=
"--enabled"
,
description
=
"Show only enabled ports"
,
required
=
false
,
multiValued
=
false
)
private
boolean
enabled
=
false
;
@Option
(
name
=
"-d"
,
aliases
=
"--disabled"
,
description
=
"Show only disabled ports"
,
required
=
false
,
multiValued
=
false
)
private
boolean
disabled
=
false
;
@Argument
(
index
=
0
,
name
=
"uri"
,
description
=
"Device ID"
,
required
=
false
,
multiValued
=
false
)
String
uri
=
null
;
...
...
@@ -61,7 +70,7 @@ public class DevicePortsListCommand extends DevicesListCommand {
* @param devices collection of devices
* @return JSON array
*/
public
static
JsonNode
jsonPorts
(
DeviceService
service
,
Iterable
<
Device
>
devices
)
{
public
JsonNode
jsonPorts
(
DeviceService
service
,
Iterable
<
Device
>
devices
)
{
ObjectMapper
mapper
=
new
ObjectMapper
();
ArrayNode
result
=
mapper
.
createArrayNode
();
for
(
Device
device
:
devices
)
{
...
...
@@ -78,25 +87,35 @@ public class DevicePortsListCommand extends DevicesListCommand {
* @param device infrastructure devices
* @return JSON array
*/
public
static
JsonNode
jsonPorts
(
DeviceService
service
,
ObjectMapper
mapper
,
Device
device
)
{
public
JsonNode
jsonPorts
(
DeviceService
service
,
ObjectMapper
mapper
,
Device
device
)
{
ObjectNode
result
=
mapper
.
createObjectNode
();
ArrayNode
ports
=
mapper
.
createArrayNode
();
for
(
Port
port
:
service
.
getPorts
(
device
.
id
()))
{
if
(
isIncluded
(
port
))
{
ports
.
add
(
mapper
.
createObjectNode
()
.
put
(
"port"
,
port
.
number
().
toString
())
.
put
(
"isEnabled"
,
port
.
isEnabled
()));
}
}
return
result
.
put
(
"device"
,
device
.
id
().
toString
()).
set
(
"ports"
,
ports
);
}
// Determines if a port should be included in output.
private
boolean
isIncluded
(
Port
port
)
{
return
enabled
&&
port
.
isEnabled
()
||
disabled
&&
!
port
.
isEnabled
()
||
!
enabled
&&
!
disabled
;
}
@Override
protected
void
printDevice
(
DeviceService
service
,
Device
device
)
{
super
.
printDevice
(
service
,
device
);
List
<
Port
>
ports
=
new
ArrayList
<>(
service
.
getPorts
(
device
.
id
()));
Collections
.
sort
(
ports
,
Comparators
.
PORT_COMPARATOR
);
for
(
Port
port
:
ports
)
{
if
(
isIncluded
(
port
))
{
print
(
FMT
,
port
.
number
(),
port
.
isEnabled
()
?
"enabled"
:
"disabled"
);
}
}
}
}
...
...
Please
register
or
login
to post a comment