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
Ayaka Koshibe
2014-09-15 11:14:52 -0700
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
43530beb187ec4cf8b9871f77a23cdd64a18973d
43530beb
1 parent
f4f463bd
Host list command added to CLI
Change-Id: I52d11d3b1d56650e92357b6cb2c67007be742114
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
109 additions
and
2 deletions
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/resources/OSGI-INF/blueprint/shell-config.xml
providers/of/host/src/main/java/org/onlab/onos/provider/of/host/impl/OpenFlowHostProvider.java
cli/src/main/java/org/onlab/onos/cli/net/HostIdCompleter.java
0 → 100644
View file @
43530be
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
;
public
class
HostIdCompleter
implements
Completer
{
@Override
public
int
complete
(
String
buffer
,
int
cursor
,
List
<
String
>
candidates
)
{
// Delegate string completer
StringsCompleter
delegate
=
new
StringsCompleter
();
HostService
service
=
AbstractShellCommand
.
get
(
HostService
.
class
);
Iterator
<
Host
>
it
=
service
.
getHosts
().
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/net/HostsListCommand.java
0 → 100644
View file @
43530be
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
;
/**
* Lists all currently-known hosts.
*/
@Command
(
scope
=
"onos"
,
name
=
"hosts"
,
description
=
"Lists all currently-known hosts."
)
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
Object
doExecute
()
throws
Exception
{
HostService
service
=
getService
(
HostService
.
class
);
for
(
Host
host
:
getSortedHosts
(
service
))
{
printHost
(
host
);
}
return
null
;
}
/**
* Returns the list of devices sorted using the device ID URIs.
*
* @param service device service
* @return sorted device list
*/
protected
List
<
Host
>
getSortedHosts
(
HostService
service
)
{
List
<
Host
>
hosts
=
newArrayList
(
service
.
getHosts
());
Collections
.
sort
(
hosts
,
ID_COMPARATOR
);
return
hosts
;
}
/**
* Prints information about a host.
*
* @param host
*/
protected
void
printHost
(
Host
host
)
{
if
(
host
!=
null
)
{
print
(
FMT
,
host
.
id
(),
host
.
mac
(),
host
.
location
().
deviceId
(),
host
.
location
().
port
(),
host
.
vlan
(),
host
.
ipAddresses
());
}
}
}
cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
View file @
43530be
...
...
@@ -55,10 +55,19 @@
<ref
component-id=
"clusterIdCompleter"
/>
</completers>
</command>
<command>
<action
class=
"org.onlab.onos.cli.net.HostsListCommand"
/>
<completers>
<ref
component-id=
"hostIdCompleter"
/>
</completers>
</command>
</command-bundle>
<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"
/>
<bean
id=
"hostIdCompleter"
class=
"org.onlab.onos.cli.net.HostIdCompleter"
/>
</blueprint>
...
...
providers/of/host/src/main/java/org/onlab/onos/provider/of/host/impl/OpenFlowHostProvider.java
View file @
43530be
...
...
@@ -19,6 +19,7 @@ import org.onlab.onos.net.host.HostProviderRegistry;
import
org.onlab.onos.net.host.HostProviderService
;
import
org.onlab.onos.net.provider.AbstractProvider
;
import
org.onlab.onos.net.provider.ProviderId
;
import
org.onlab.onos.of.controller.Dpid
;
import
org.onlab.onos.of.controller.OpenFlowController
;
import
org.onlab.onos.of.controller.OpenFlowPacketContext
;
import
org.onlab.onos.of.controller.PacketListener
;
...
...
@@ -61,7 +62,7 @@ public class OpenFlowHostProvider extends AbstractProvider implements HostProvid
@Activate
public
void
activate
()
{
providerService
=
providerRegistry
.
register
(
this
);
controller
.
addPacketListener
(
0
,
listener
);
controller
.
addPacketListener
(
1
0
,
listener
);
log
.
info
(
"Started"
);
}
...
...
@@ -92,7 +93,7 @@ public class OpenFlowHostProvider extends AbstractProvider implements HostProvid
HostId
hid
=
HostId
.
hostId
(
eth
.
getSourceMAC
(),
vlan
);
HostLocation
hloc
=
new
HostLocation
(
DeviceId
.
deviceId
(
"of:"
+
Long
.
toHexString
(
pktCtx
.
dpid
().
value
())),
DeviceId
.
deviceId
(
Dpid
.
uri
(
pktCtx
.
dpid
())),
PortNumber
.
portNumber
(
pktCtx
.
inPort
()),
System
.
currentTimeMillis
());
ARP
arp
=
(
ARP
)
eth
.
getPayload
();
...
...
Please
register
or
login
to post a comment