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-21 10:01:49 -0700
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
6ce7304822016147c5a12158077025800f18504f
6ce73048
1 parent
7772e109
Adding JSON output for intent list command.
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
128 additions
and
4 deletions
cli/src/main/java/org/onlab/onos/cli/net/IntentsListCommand.java
cli/src/main/java/org/onlab/onos/cli/net/IntentsListCommand.java
View file @
6ce7304
package
org
.
onlab
.
onos
.
cli
.
net
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.node.ArrayNode
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
org.apache.karaf.shell.commands.Command
;
import
org.onlab.onos.cli.AbstractShellCommand
;
import
org.onlab.onos.net.ConnectPoint
;
import
org.onlab.onos.net.Link
;
import
org.onlab.onos.net.NetworkResource
;
import
org.onlab.onos.net.intent.ConnectivityIntent
;
import
org.onlab.onos.net.intent.Intent
;
import
org.onlab.onos.net.intent.IntentService
;
import
org.onlab.onos.net.intent.IntentState
;
import
org.onlab.onos.net.intent.LinkCollectionIntent
;
import
org.onlab.onos.net.intent.MultiPointToSinglePointIntent
;
import
org.onlab.onos.net.intent.PathIntent
;
import
org.onlab.onos.net.intent.PointToPointIntent
;
import
org.onlab.onos.net.intent.SinglePointToMultiPointIntent
;
import
java.util.Set
;
/**
* Lists the inventory of intents and their states.
...
...
@@ -16,11 +31,120 @@ public class IntentsListCommand extends AbstractShellCommand {
@Override
protected
void
execute
()
{
IntentService
service
=
get
(
IntentService
.
class
);
for
(
Intent
intent
:
service
.
getIntents
())
{
IntentState
state
=
service
.
getIntentState
(
intent
.
id
());
print
(
"id=%s, state=%s, appId=%s, %s"
,
intent
.
id
(),
state
,
intent
.
appId
().
name
(),
intent
);
if
(
outputJson
())
{
print
(
"%s"
,
json
(
service
,
service
.
getIntents
()));
}
else
{
for
(
Intent
intent
:
service
.
getIntents
())
{
IntentState
state
=
service
.
getIntentState
(
intent
.
id
());
print
(
"id=%s, state=%s, type=%s, appId=%s"
,
intent
.
id
(),
state
,
intent
.
getClass
().
getSimpleName
(),
intent
.
appId
().
name
());
printDetails
(
intent
);
}
}
}
private
void
printDetails
(
Intent
intent
)
{
if
(
intent
.
resources
()
!=
null
&&
!
intent
.
resources
().
isEmpty
())
{
print
(
" resources=%s"
,
intent
.
resources
());
}
if
(
intent
instanceof
ConnectivityIntent
)
{
ConnectivityIntent
ci
=
(
ConnectivityIntent
)
intent
;
print
(
" selector=%s"
,
ci
.
selector
().
criteria
());
print
(
" treatment=%s"
,
ci
.
treatment
().
instructions
());
}
if
(
intent
instanceof
PointToPointIntent
)
{
PointToPointIntent
pi
=
(
PointToPointIntent
)
intent
;
print
(
" ingress=%s, egress=%s"
,
pi
.
ingressPoint
(),
pi
.
egressPoint
());
}
else
if
(
intent
instanceof
MultiPointToSinglePointIntent
)
{
MultiPointToSinglePointIntent
pi
=
(
MultiPointToSinglePointIntent
)
intent
;
print
(
" ingress=%s, egress=%s"
,
pi
.
ingressPoints
(),
pi
.
egressPoint
());
}
else
if
(
intent
instanceof
SinglePointToMultiPointIntent
)
{
SinglePointToMultiPointIntent
pi
=
(
SinglePointToMultiPointIntent
)
intent
;
print
(
" ingress=%s, egress=%s"
,
pi
.
ingressPoint
(),
pi
.
egressPoints
());
}
else
if
(
intent
instanceof
PathIntent
)
{
PathIntent
pi
=
(
PathIntent
)
intent
;
print
(
" path=%s, cost=%d"
,
pi
.
path
().
links
(),
pi
.
path
().
cost
());
}
else
if
(
intent
instanceof
LinkCollectionIntent
)
{
LinkCollectionIntent
li
=
(
LinkCollectionIntent
)
intent
;
print
(
" links=%s"
,
li
.
links
());
print
(
" egress=%s"
,
li
.
egressPoint
());
}
}
// Produces JSON array of the specified intents.
private
JsonNode
json
(
IntentService
service
,
Iterable
<
Intent
>
intents
)
{
ObjectMapper
mapper
=
new
ObjectMapper
();
ArrayNode
result
=
mapper
.
createArrayNode
();
for
(
Intent
intent
:
intents
)
{
result
.
add
(
json
(
service
,
mapper
,
intent
));
}
return
result
;
}
private
JsonNode
json
(
IntentService
service
,
ObjectMapper
mapper
,
Intent
intent
)
{
ObjectNode
result
=
mapper
.
createObjectNode
()
.
put
(
"id"
,
intent
.
id
().
toString
())
.
put
(
"state"
,
service
.
getIntentState
(
intent
.
id
()).
toString
())
.
put
(
"type"
,
intent
.
getClass
().
getSimpleName
())
.
put
(
"appId"
,
intent
.
appId
().
name
());
if
(
intent
.
resources
()
!=
null
&&
!
intent
.
resources
().
isEmpty
())
{
ArrayNode
rnode
=
mapper
.
createArrayNode
();
for
(
NetworkResource
resource
:
intent
.
resources
())
{
rnode
.
add
(
resource
.
toString
());
}
result
.
set
(
"resources"
,
rnode
);
}
if
(
intent
instanceof
ConnectivityIntent
)
{
ConnectivityIntent
ci
=
(
ConnectivityIntent
)
intent
;
if
(!
ci
.
selector
().
criteria
().
isEmpty
())
{
result
.
put
(
"selector"
,
ci
.
selector
().
criteria
().
toString
());
}
if
(!
ci
.
treatment
().
instructions
().
isEmpty
())
{
result
.
put
(
"treatment"
,
ci
.
treatment
().
instructions
().
toString
());
}
}
if
(
intent
instanceof
PathIntent
)
{
PathIntent
pi
=
(
PathIntent
)
intent
;
ArrayNode
pnode
=
mapper
.
createArrayNode
();
for
(
Link
link
:
pi
.
path
().
links
())
{
pnode
.
add
(
link
.
toString
());
}
result
.
set
(
"path"
,
pnode
);
}
else
if
(
intent
instanceof
PointToPointIntent
)
{
PointToPointIntent
pi
=
(
PointToPointIntent
)
intent
;
result
.
set
(
"ingress"
,
LinksListCommand
.
json
(
mapper
,
pi
.
ingressPoint
()));
result
.
set
(
"egress"
,
LinksListCommand
.
json
(
mapper
,
pi
.
egressPoint
()));
}
else
if
(
intent
instanceof
MultiPointToSinglePointIntent
)
{
MultiPointToSinglePointIntent
pi
=
(
MultiPointToSinglePointIntent
)
intent
;
result
.
set
(
"ingress"
,
json
(
mapper
,
pi
.
ingressPoints
()));
result
.
set
(
"egress"
,
LinksListCommand
.
json
(
mapper
,
pi
.
egressPoint
()));
}
else
if
(
intent
instanceof
SinglePointToMultiPointIntent
)
{
SinglePointToMultiPointIntent
pi
=
(
SinglePointToMultiPointIntent
)
intent
;
result
.
set
(
"ingress"
,
LinksListCommand
.
json
(
mapper
,
pi
.
ingressPoint
()));
result
.
set
(
"egress"
,
json
(
mapper
,
pi
.
egressPoints
()));
}
else
if
(
intent
instanceof
LinkCollectionIntent
)
{
LinkCollectionIntent
li
=
(
LinkCollectionIntent
)
intent
;
result
.
set
(
"links"
,
LinksListCommand
.
json
(
li
.
links
()));
}
return
result
;
}
private
JsonNode
json
(
ObjectMapper
mapper
,
Set
<
ConnectPoint
>
connectPoints
)
{
ArrayNode
result
=
mapper
.
createArrayNode
();
for
(
ConnectPoint
cp
:
connectPoints
)
{
result
.
add
(
LinksListCommand
.
json
(
mapper
,
cp
));
}
return
result
;
}
}
...
...
Please
register
or
login
to post a comment