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-08 01:50:20 -0700
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
6d2a43e4d8d048ad5c8f1345d0a8b6963577bd50
6d2a43e4
1 parent
c0ccfb21
Added some CLI commands and fixed pom.xml and features.xml to use commons-lang 2.6 (bundle)
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
175 additions
and
14 deletions
cli/src/main/java/org/onlab/onos/cli/AbstractShellCommand.java
cli/src/main/java/org/onlab/onos/cli/GreetCommand.java
cli/src/main/java/org/onlab/onos/cli/net/DeviceIdCompleter.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/LinksListCommand.java
cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
features/features.xml
pom.xml
utils/misc/pom.xml
utils/pom.xml
cli/src/main/java/org/onlab/onos/cli/AbstractShellCommand.java
View file @
6d2a43e
...
...
@@ -10,15 +10,25 @@ import org.osgi.framework.FrameworkUtil;
public
abstract
class
AbstractShellCommand
extends
OsgiCommandSupport
{
/**
* Returns the reference to the implementa
it
on of the specified service.
* Returns the reference to the implementa
ti
on of the specified service.
*
* @param serviceClass service class
* @param <T> type of service
* @return service implementation
*/
static
<
T
>
T
get
(
Class
<
T
>
serviceClass
)
{
public
static
<
T
>
T
get
(
Class
<
T
>
serviceClass
)
{
BundleContext
bc
=
FrameworkUtil
.
getBundle
(
AbstractShellCommand
.
class
).
getBundleContext
();
return
bc
.
getService
(
bc
.
getServiceReference
(
serviceClass
));
}
/**
* Prints the arguments using the specified format.
*
* @param format format string; see {@link String#format}
* @param args arguments
*/
public
static
void
print
(
String
format
,
Object
...
args
)
{
System
.
out
.
println
(
String
.
format
(
format
,
args
));
}
}
...
...
cli/src/main/java/org/onlab/onos/cli/GreetCommand.java
View file @
6d2a43e
...
...
@@ -2,7 +2,6 @@ package org.onlab.onos.cli;
import
org.apache.karaf.shell.commands.Argument
;
import
org.apache.karaf.shell.commands.Command
;
import
org.apache.karaf.shell.console.OsgiCommandSupport
;
import
org.onlab.onos.GreetService
;
/**
...
...
@@ -10,7 +9,7 @@ import org.onlab.onos.GreetService;
* use of an optional parameter as well.
*/
@Command
(
scope
=
"onos"
,
name
=
"greet"
,
description
=
"Issues a greeting"
)
public
class
GreetCommand
extends
OsgiCommandSupport
{
public
class
GreetCommand
extends
AbstractShellCommand
{
@Argument
(
index
=
0
,
name
=
"name"
,
description
=
"Name to greet"
,
required
=
false
,
multiValued
=
false
)
...
...
@@ -18,7 +17,7 @@ public class GreetCommand extends OsgiCommandSupport {
@Override
protected
Object
doExecute
()
throws
Exception
{
System
.
out
.
println
(
getService
(
GreetService
.
class
).
yo
(
name
));
print
(
getService
(
GreetService
.
class
).
yo
(
name
));
return
null
;
}
}
...
...
cli/src/main/java/org/onlab/onos/cli/net/DeviceIdCompleter.java
0 → 100644
View file @
6d2a43e
package
org
.
onlab
.
onos
.
cli
.
net
;
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.Device
;
import
org.onlab.onos.net.device.DeviceService
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.SortedSet
;
/**
* Device ID completer.
*/
public
class
DeviceIdCompleter
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
DeviceService
service
=
AbstractShellCommand
.
get
(
DeviceService
.
class
);
Iterator
<
Device
>
it
=
service
.
getDevices
().
iterator
();
SortedSet
<
String
>
strings
=
delegate
.
getStrings
();
while
(
it
.
hasNext
())
{
strings
.
add
(
it
.
next
().
id
().
uri
().
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/net/DevicePortsListCommand.java
0 → 100644
View file @
6d2a43e
package
org
.
onlab
.
onos
.
cli
.
net
;
import
org.apache.karaf.shell.commands.Argument
;
import
org.apache.karaf.shell.commands.Command
;
import
org.onlab.onos.cli.AbstractShellCommand
;
import
org.onlab.onos.net.Port
;
import
org.onlab.onos.net.device.DeviceService
;
import
static
org
.
onlab
.
onos
.
net
.
DeviceId
.
deviceId
;
/**
* Lists all infrastructure links.
*/
@Command
(
scope
=
"onos"
,
name
=
"ports"
,
description
=
"Lists all ports of a device"
)
public
class
DevicePortsListCommand
extends
AbstractShellCommand
{
private
static
final
String
FMT
=
"port=%s, state=%s"
;
@Argument
(
index
=
0
,
name
=
"deviceId"
,
description
=
"Device ID"
,
required
=
true
,
multiValued
=
false
)
String
deviceId
=
null
;
@Override
protected
Object
doExecute
()
throws
Exception
{
DeviceService
service
=
getService
(
DeviceService
.
class
);
Iterable
<
Port
>
ports
=
service
.
getPorts
(
deviceId
(
deviceId
));
for
(
Port
port
:
ports
)
{
print
(
FMT
,
port
.
number
(),
port
.
isEnabled
()
?
"enabled"
:
"disabled"
);
}
return
null
;
}
}
cli/src/main/java/org/onlab/onos/cli/net/DevicesListCommand.java
0 → 100644
View file @
6d2a43e
package
org
.
onlab
.
onos
.
cli
.
net
;
import
org.apache.karaf.shell.commands.Command
;
import
org.onlab.onos.cli.AbstractShellCommand
;
import
org.onlab.onos.net.Device
;
import
org.onlab.onos.net.device.DeviceService
;
/**
* Lists all infrastructure devices.
*/
@Command
(
scope
=
"onos"
,
name
=
"devices"
,
description
=
"Lists all infrastructure devices"
)
public
class
DevicesListCommand
extends
AbstractShellCommand
{
private
static
final
String
FMT
=
"id=%s, type=%s, mfr=%s, hw=%s, sw=%s, serial=%s"
;
@Override
protected
Object
doExecute
()
throws
Exception
{
for
(
Device
device
:
getService
(
DeviceService
.
class
).
getDevices
())
{
print
(
FMT
,
device
.
id
(),
device
.
type
(),
device
.
manufacturer
(),
device
.
hwVersion
(),
device
.
swVersion
(),
device
.
serialNumber
());
}
return
null
;
}
}
cli/src/main/java/org/onlab/onos/cli/net/LinksListCommand.java
0 → 100644
View file @
6d2a43e
package
org
.
onlab
.
onos
.
cli
.
net
;
import
org.apache.karaf.shell.commands.Argument
;
import
org.apache.karaf.shell.commands.Command
;
import
org.onlab.onos.cli.AbstractShellCommand
;
import
org.onlab.onos.net.Link
;
import
org.onlab.onos.net.link.LinkService
;
import
static
org
.
onlab
.
onos
.
net
.
DeviceId
.
deviceId
;
/**
* Lists all infrastructure links.
*/
@Command
(
scope
=
"onos"
,
name
=
"links"
,
description
=
"Lists all infrastructure links"
)
public
class
LinksListCommand
extends
AbstractShellCommand
{
private
static
final
String
FMT
=
"src=%s/%s, dst=%s/%s, type=%s"
;
@Argument
(
index
=
0
,
name
=
"deviceId"
,
description
=
"Device ID"
,
required
=
false
,
multiValued
=
false
)
String
deviceId
=
null
;
@Override
protected
Object
doExecute
()
throws
Exception
{
LinkService
service
=
getService
(
LinkService
.
class
);
Iterable
<
Link
>
links
=
deviceId
!=
null
?
service
.
getDeviceLinks
(
deviceId
(
deviceId
))
:
service
.
getLinks
();
for
(
Link
link
:
links
)
{
print
(
FMT
,
link
.
src
().
deviceId
(),
link
.
src
().
port
(),
link
.
dst
().
deviceId
(),
link
.
dst
().
port
(),
link
.
type
());
}
return
null
;
}
}
cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
View file @
6d2a43e
...
...
@@ -2,13 +2,31 @@
<command-bundle
xmlns=
"http://karaf.apache.org/xmlns/shell/v1.1.0"
>
<command>
<action
class=
"org.onlab.onos.cli.GreetCommand"
/>
<action
class=
"org.onlab.onos.cli.net.DevicesListCommand"
/>
</command>
<command>
<action
class=
"org.onlab.onos.cli.net.DevicePortsListCommand"
/>
<completers>
<ref
component-id=
"deviceIdCompleter"
/>
</completers>
</command>
<command>
<action
class=
"org.onlab.onos.cli.net.LinksListCommand"
/>
<completers>
<ref
component-id=
"
name
Completer"
/>
<ref
component-id=
"
deviceId
Completer"
/>
</completers>
</command>
<!--<command>-->
<!--<action class="org.onlab.onos.cli.GreetCommand"/>-->
<!--<completers>-->
<!--<ref component-id="nameCompleter"/>-->
<!--</completers>-->
<!--</command>-->
</command-bundle>
<bean
id=
"deviceIdCompleter"
class=
"org.onlab.onos.cli.net.DeviceIdCompleter"
/>
<bean
id=
"nameCompleter"
class=
"org.onlab.onos.cli.NameCompleter"
/>
</blueprint>
...
...
features/features.xml
View file @
6d2a43e
...
...
@@ -5,7 +5,8 @@
<feature
name=
"onos-thirdparty-base"
version=
"1.0.0"
description=
"ONOS 3rd party dependencies"
>
<bundle>
mvn:com.google.guava/guava/17.0
</bundle>
<bundle>
mvn:commons-lang/commons-lang/2.6
</bundle>
<bundle>
mvn:com.google.guava/guava/18.0
</bundle>
</feature>
<feature
name=
"onos-thirdparty-web"
version=
"1.0.0"
...
...
pom.xml
View file @
6d2a43e
...
...
@@ -68,6 +68,11 @@
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
commons-lang
</groupId>
<artifactId>
commons-lang
</artifactId>
<version>
2.6
</version>
</dependency>
<!-- Web related -->
<dependency>
...
...
utils/misc/pom.xml
View file @
6d2a43e
...
...
@@ -20,9 +20,13 @@
<dependency>
<groupId>
com.google.guava
</groupId>
<artifactId>
guava-testlib
</artifactId>
<version>
17.0
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
commons-lang
</groupId>
<artifactId>
commons-lang
</artifactId>
</dependency>
</dependencies>
</project>
...
...
utils/pom.xml
View file @
6d2a43e
...
...
@@ -27,11 +27,6 @@
<groupId>
com.google.guava
</groupId>
<artifactId>
guava
</artifactId>
</dependency>
<dependency>
<groupId>
commons-lang
</groupId>
<artifactId>
commons-lang
</artifactId>
<version>
2.3
</version>
</dependency>
</dependencies>
<build>
...
...
Please
register
or
login
to post a comment