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
alshabib
2014-09-25 18:44:02 -0700
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
144a2948a92fb1a5b3d8a0d5b981d4a1235f73da
144a2948
1 parent
a12c8c89
flow cmd has state selector
Change-Id: Id778277979d538e4addf8ed0052066a6d2e67ac6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
4 deletions
cli/src/main/java/org/onlab/onos/cli/net/FlowRuleStatusCompleter.java
cli/src/main/java/org/onlab/onos/cli/net/FlowsListCommand.java
cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
cli/src/main/java/org/onlab/onos/cli/net/FlowRuleStatusCompleter.java
0 → 100644
View file @
144a294
package
org
.
onlab
.
onos
.
cli
.
net
;
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.net.flow.FlowRule.FlowRuleState
;
/**
* Device ID completer.
*/
public
class
FlowRuleStatusCompleter
implements
Completer
{
@Override
public
int
complete
(
String
buffer
,
int
cursor
,
List
<
String
>
candidates
)
{
// Delegate string completer
StringsCompleter
delegate
=
new
StringsCompleter
();
FlowRuleState
[]
states
=
FlowRuleState
.
values
();
SortedSet
<
String
>
strings
=
delegate
.
getStrings
();
for
(
int
i
=
0
;
i
<
states
.
length
;
i
++)
{
strings
.
add
(
states
[
i
].
toString
().
toLowerCase
());
}
strings
.
add
(
FlowsListCommand
.
ANY
);
// 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/net/FlowsListCommand.java
View file @
144a294
...
...
@@ -13,6 +13,7 @@ import org.onlab.onos.net.Device;
import
org.onlab.onos.net.DeviceId
;
import
org.onlab.onos.net.device.DeviceService
;
import
org.onlab.onos.net.flow.FlowRule
;
import
org.onlab.onos.net.flow.FlowRule.FlowRuleState
;
import
org.onlab.onos.net.flow.FlowRuleService
;
import
com.google.common.collect.Maps
;
...
...
@@ -24,15 +25,20 @@ import com.google.common.collect.Maps;
description
=
"Lists all currently-known flows."
)
public
class
FlowsListCommand
extends
AbstractShellCommand
{
public
static
final
String
ANY
=
"any"
;
private
static
final
String
FMT
=
" id=%s, state=%s, bytes=%s, packets=%s, duration=%s, priority=%s"
;
private
static
final
String
TFMT
=
" treatment=%s"
;
private
static
final
String
SFMT
=
" selector=%s"
;
@Argument
(
index
=
0
,
name
=
"uri"
,
description
=
"Device ID"
,
@Argument
(
index
=
1
,
name
=
"uri"
,
description
=
"Device ID"
,
required
=
false
,
multiValued
=
false
)
String
uri
=
null
;
@Argument
(
index
=
0
,
name
=
"state"
,
description
=
"Flow Rule state"
,
required
=
false
,
multiValued
=
false
)
String
state
=
null
;
@Override
protected
void
execute
()
{
...
...
@@ -52,11 +58,24 @@ public class FlowsListCommand extends AbstractShellCommand {
*/
protected
Map
<
Device
,
List
<
FlowRule
>>
getSortedFlows
(
DeviceService
deviceService
,
FlowRuleService
service
)
{
Map
<
Device
,
List
<
FlowRule
>>
flows
=
Maps
.
newHashMap
();
List
<
FlowRule
>
rules
=
newArrayList
();
List
<
FlowRule
>
rules
;
FlowRuleState
s
=
null
;
if
(
state
!=
null
&&
!
state
.
equals
(
"any"
))
{
s
=
FlowRuleState
.
valueOf
(
state
.
toUpperCase
());
}
Iterable
<
Device
>
devices
=
uri
==
null
?
deviceService
.
getDevices
()
:
Collections
.
singletonList
(
deviceService
.
getDevice
(
DeviceId
.
deviceId
(
uri
)));
for
(
Device
d
:
devices
)
{
rules
=
newArrayList
(
service
.
getFlowEntries
(
d
.
id
()));
if
(
s
==
null
)
{
rules
=
newArrayList
(
service
.
getFlowEntries
(
d
.
id
()));
}
else
{
rules
=
newArrayList
();
for
(
FlowRule
f
:
service
.
getFlowEntries
(
d
.
id
()))
{
if
(
f
.
state
().
equals
(
s
))
{
rules
.
add
(
f
);
}
}
}
Collections
.
sort
(
rules
,
Comparators
.
FLOW_RULE_COMPARATOR
);
flows
.
put
(
d
,
rules
);
}
...
...
@@ -71,7 +90,7 @@ public class FlowsListCommand extends AbstractShellCommand {
protected
void
printFlows
(
Device
d
,
List
<
FlowRule
>
flows
)
{
print
(
"Device: "
+
d
.
id
());
if
(
flows
==
null
|
flows
.
isEmpty
())
{
print
(
" %s"
,
"No flows
installed
."
);
print
(
" %s"
,
"No flows."
);
return
;
}
for
(
FlowRule
f
:
flows
)
{
...
...
cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
View file @
144a294
...
...
@@ -73,6 +73,7 @@
<command>
<action
class=
"org.onlab.onos.cli.net.FlowsListCommand"
/>
<completers>
<ref
component-id=
"flowRuleStatusCompleter"
/>
<ref
component-id=
"deviceIdCompleter"
/>
</completers>
</command>
...
...
@@ -87,5 +88,6 @@
<bean
id=
"clusterIdCompleter"
class=
"org.onlab.onos.cli.net.ClusterIdCompleter"
/>
<bean
id=
"roleCompleter"
class=
"org.onlab.onos.cli.net.RoleCompleter"
/>
<bean
id=
"hostIdCompleter"
class=
"org.onlab.onos.cli.net.HostIdCompleter"
/>
<bean
id=
"flowRuleStatusCompleter"
class=
"org.onlab.onos.cli.net.FlowRuleStatusCompleter"
/>
</blueprint>
...
...
Please
register
or
login
to post a comment