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-11 15:13:19 -0700
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
c6ed809348613b1d2d164100a18720e5073fd99b
c6ed8093
2 parents
fe2dd7e6
04a1a4e4
Merge branch 'master' of
ssh://gerrit.onlab.us:29418/onos-next
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
216 additions
and
32 deletions
core/api/src/main/java/org/onlab/onos/net/DefaultHost.java
core/api/src/main/java/org/onlab/onos/net/Host.java
core/api/src/main/java/org/onlab/onos/net/host/DefaultHostDescription.java
core/api/src/main/java/org/onlab/onos/net/host/HostDescription.java
core/api/src/main/java/org/onlab/onos/net/host/HostService.java
core/trivial/src/main/java/org/onlab/onos/net/trivial/host/impl/SimpleHostManager.java
core/trivial/src/main/java/org/onlab/onos/net/trivial/host/impl/SimpleHostStore.java
utils/misc/src/main/java/org/onlab/packet/IPAddress.java
utils/misc/src/main/java/org/onlab/packet/VLANID.java
core/api/src/main/java/org/onlab/onos/net/DefaultHost.java
View file @
c6ed809
...
...
@@ -8,23 +8,27 @@ import java.util.Objects;
import
java.util.Set
;
import
org.onlab.onos.net.provider.ProviderId
;
import
org.onlab.packet.IP
v4
;
import
org.onlab.packet.IP
Address
;
import
org.onlab.packet.MACAddress
;
import
org.onlab.packet.VLANID
;
/**
* A basic implementation of a Host.
*/
public
class
DefaultHost
extends
AbstractElement
implements
Host
{
private
final
MACAddress
mac
;
private
final
short
vlan
;
private
final
VLANID
vlan
;
private
final
HostLocation
location
;
private
final
Set
<
IP
v4
>
ips
;
private
final
Set
<
IP
Address
>
ips
;
public
DefaultHost
(
ProviderId
providerId
,
Elemen
tId
id
,
MACAddress
mac
,
short
vlan
,
HostLocation
loc
,
Set
<
IPv4
>
ips
)
{
public
DefaultHost
(
ProviderId
providerId
,
Hos
tId
id
,
MACAddress
mac
,
VLANID
vlan
,
HostLocation
loc
,
Set
<
IPAddress
>
ips
)
{
super
(
providerId
,
id
);
this
.
mac
=
mac
;
this
.
vlan
=
vlan
;
this
.
location
=
loc
;
this
.
ips
=
new
HashSet
<
IP
v4
>(
ips
);
this
.
ips
=
new
HashSet
<
IP
Address
>(
ips
);
}
@Override
...
...
@@ -38,7 +42,7 @@ public class DefaultHost extends AbstractElement implements Host {
}
@Override
public
Set
<
IP
v4
>
ipAddresses
()
{
public
Set
<
IP
Address
>
ipAddresses
()
{
return
Collections
.
unmodifiableSet
(
ips
);
}
...
...
@@ -48,7 +52,7 @@ public class DefaultHost extends AbstractElement implements Host {
}
@Override
public
short
vlan
()
{
public
VLANID
vlan
()
{
return
vlan
;
}
...
...
core/api/src/main/java/org/onlab/onos/net/Host.java
View file @
c6ed809
package
org
.
onlab
.
onos
.
net
;
import
org.onlab.packet.IP
v4
;
import
org.onlab.packet.IP
Address
;
import
org.onlab.packet.MACAddress
;
import
org.onlab.packet.VLANID
;
import
java.util.Set
;
...
...
@@ -15,6 +16,7 @@ public interface Host extends Element {
*
* @return host id
*/
@Override
HostId
id
();
/**
...
...
@@ -29,14 +31,14 @@ public interface Host extends Element {
*
* @return VLAN ID value
*/
short
vlan
();
VLANID
vlan
();
/**
* Returns set of IP addresses currently bound to the host MAC address.
*
* @return set of IP addresses; empty if no IP address is bound
*/
Set
<
IP
v4
>
ipAddresses
();
Set
<
IP
Address
>
ipAddresses
();
/**
* Returns the most recent host location where the host attaches to the
...
...
core/api/src/main/java/org/onlab/onos/net/host/DefaultHostDescription.java
View file @
c6ed809
...
...
@@ -6,24 +6,25 @@ import java.util.HashSet;
import
java.util.Set
;
import
org.onlab.onos.net.HostLocation
;
import
org.onlab.packet.IP
v4
;
import
org.onlab.packet.IP
Address
;
import
org.onlab.packet.MACAddress
;
import
org.onlab.packet.VLANID
;
import
com.google.common.collect.ImmutableSet
;
public
class
DefaultHostDescription
implements
HostDescription
{
private
final
MACAddress
mac
;
private
final
short
vlan
;
private
final
VLANID
vlan
;
private
final
HostLocation
location
;
private
final
Set
<
IP
v4
>
ips
;
private
final
Set
<
IP
Address
>
ips
;
public
DefaultHostDescription
(
MACAddress
mac
,
short
vlan
,
HostLocation
loc
,
Set
<
IP
v4
>
ips
)
{
public
DefaultHostDescription
(
MACAddress
mac
,
VLANID
vlan
,
HostLocation
loc
,
Set
<
IP
Address
>
ips
)
{
this
.
mac
=
mac
;
this
.
vlan
=
vlan
;
this
.
location
=
loc
;
this
.
ips
=
new
HashSet
<
IP
v4
>(
ips
);
this
.
ips
=
new
HashSet
<
IP
Address
>(
ips
);
}
@Override
...
...
@@ -32,7 +33,7 @@ public class DefaultHostDescription implements HostDescription {
}
@Override
public
short
vlan
()
{
public
VLANID
vlan
()
{
return
vlan
;
}
...
...
@@ -42,7 +43,7 @@ public class DefaultHostDescription implements HostDescription {
}
@Override
public
Set
<
IP
v4
>
ipAddresses
()
{
public
Set
<
IP
Address
>
ipAddresses
()
{
return
ImmutableSet
.
copyOf
(
ips
);
}
...
...
core/api/src/main/java/org/onlab/onos/net/host/HostDescription.java
View file @
c6ed809
...
...
@@ -4,8 +4,9 @@ import java.util.Set;
import
org.onlab.onos.net.Description
;
import
org.onlab.onos.net.HostLocation
;
import
org.onlab.packet.IP
v4
;
import
org.onlab.packet.IP
Address
;
import
org.onlab.packet.MACAddress
;
import
org.onlab.packet.VLANID
;
/**
* Information describing host and its location.
...
...
@@ -24,7 +25,7 @@ public interface HostDescription extends Description {
*
* @return the VLAN ID value
*/
short
vlan
();
VLANID
vlan
();
/**
* Returns the location of the host on the network edge.
...
...
@@ -38,6 +39,6 @@ public interface HostDescription extends Description {
*
* @return a set of IP addresses.
*/
Set
<
IP
v4
>
ipAddresses
();
Set
<
IP
Address
>
ipAddresses
();
}
...
...
core/api/src/main/java/org/onlab/onos/net/host/HostService.java
View file @
c6ed809
...
...
@@ -4,8 +4,9 @@ import org.onlab.onos.net.ConnectPoint;
import
org.onlab.onos.net.DeviceId
;
import
org.onlab.onos.net.Host
;
import
org.onlab.onos.net.HostId
;
import
org.onlab.packet.IP
v4
;
import
org.onlab.packet.IP
Address
;
import
org.onlab.packet.MACAddress
;
import
org.onlab.packet.VLANID
;
import
java.util.Set
;
...
...
@@ -43,7 +44,7 @@ public interface HostService {
* @return set of hosts in the given vlan id
*/
// FIXME: change long to VLanId
Set
<
Host
>
getHostsByVlan
(
long
vlanId
);
Set
<
Host
>
getHostsByVlan
(
VLANID
vlanId
);
/**
* Returns the set of hosts that have the specified MAC address.
...
...
@@ -59,7 +60,7 @@ public interface HostService {
* @param ip ip address
* @return set of hosts with the given IP
*/
Set
<
Host
>
getHostsByIp
(
IP
v4
ip
);
Set
<
Host
>
getHostsByIp
(
IP
Address
ip
);
/**
* Returns the set of hosts whose most recent location is the specified
...
...
core/trivial/src/main/java/org/onlab/onos/net/trivial/host/impl/SimpleHostManager.java
View file @
c6ed809
...
...
@@ -21,8 +21,9 @@ import org.onlab.onos.net.host.HostProviderService;
import
org.onlab.onos.net.host.HostService
;
import
org.onlab.onos.net.provider.AbstractProviderRegistry
;
import
org.onlab.onos.net.provider.AbstractProviderService
;
import
org.onlab.packet.IP
v4
;
import
org.onlab.packet.IP
Address
;
import
org.onlab.packet.MACAddress
;
import
org.onlab.packet.VLANID
;
import
org.slf4j.Logger
;
import
java.util.Set
;
...
...
@@ -85,7 +86,7 @@ public class SimpleHostManager
}
@Override
public
Set
<
Host
>
getHostsByVlan
(
long
vlanId
)
{
public
Set
<
Host
>
getHostsByVlan
(
VLANID
vlanId
)
{
return
store
.
getHosts
(
vlanId
);
}
...
...
@@ -96,7 +97,7 @@ public class SimpleHostManager
}
@Override
public
Set
<
Host
>
getHostsByIp
(
IP
v4
ip
)
{
public
Set
<
Host
>
getHostsByIp
(
IP
Address
ip
)
{
checkNotNull
(
ip
,
"IP address cannot be null"
);
return
store
.
getHosts
(
ip
);
}
...
...
core/trivial/src/main/java/org/onlab/onos/net/trivial/host/impl/SimpleHostStore.java
View file @
c6ed809
...
...
@@ -19,8 +19,9 @@ import org.onlab.onos.net.HostId;
import
org.onlab.onos.net.host.HostDescription
;
import
org.onlab.onos.net.host.HostEvent
;
import
org.onlab.onos.net.provider.ProviderId
;
import
org.onlab.packet.IP
v4
;
import
org.onlab.packet.IP
Address
;
import
org.onlab.packet.MACAddress
;
import
org.onlab.packet.VLANID
;
import
com.google.common.collect.HashMultimap
;
import
com.google.common.collect.ImmutableSet
;
...
...
@@ -149,10 +150,10 @@ public class SimpleHostStore {
* @param vlanId vlan id
* @return set of hosts in the vlan
*/
Set
<
Host
>
getHosts
(
long
vlanId
)
{
Set
<
Host
>
getHosts
(
VLANID
vlanId
)
{
Set
<
Host
>
vlanset
=
new
HashSet
<
Host
>();
for
(
Host
h
:
hosts
.
values
())
{
if
(
h
.
vlan
()
==
vlanId
)
{
if
(
h
.
vlan
()
.
equals
(
vlanId
)
)
{
vlanset
.
add
(
h
);
}
}
...
...
@@ -181,7 +182,7 @@ public class SimpleHostStore {
* @param ip ip address
* @return set of hosts with the given IP
*/
Set
<
Host
>
getHosts
(
IP
v4
ip
)
{
Set
<
Host
>
getHosts
(
IP
Address
ip
)
{
Set
<
Host
>
ipset
=
new
HashSet
<>();
for
(
Host
h
:
hosts
.
values
())
{
if
(
h
.
ipAddresses
().
contains
(
ip
))
{
...
...
utils/misc/src/main/java/org/onlab/packet/IPAddress.java
0 → 100644
View file @
c6ed809
package
org
.
onlab
.
packet
;
import
java.util.Arrays
;
/**
* A class representing an IPv4 address.
*/
public
class
IPAddress
{
//IP Versions
public
enum
Version
{
INET
,
INET6
};
//lengths of address, in bytes
public
static
final
int
INET_LEN
=
4
;
public
static
final
int
INET6_LEN
=
6
;
protected
Version
version
;
//does it make more sense to have a integral address?
protected
byte
[]
octets
;
protected
IPAddress
(
Version
ver
,
byte
[]
octets
)
{
this
.
version
=
ver
;
this
.
octets
=
Arrays
.
copyOf
(
octets
,
INET_LEN
);
}
/**
* Converts a byte array into an IP address.
*
* @param address a byte array
* @return an IP address
*/
public
static
IPAddress
valueOf
(
byte
[]
address
)
{
return
new
IPAddress
(
Version
.
INET
,
address
);
}
/**
* Converts an integer into an IPv4 address.
*
* @param address an integer representing an IP value
* @return an IP address
*/
public
static
IPAddress
valueOf
(
int
address
)
{
byte
[]
bytes
=
new
byte
[]
{
(
byte
)
((
address
>>
24
)
&
0xff
),
(
byte
)
((
address
>>
16
)
&
0xff
),
(
byte
)
((
address
>>
8
)
&
0xff
),
(
byte
)
((
address
>>
0
)
&
0xff
)
};
return
new
IPAddress
(
Version
.
INET
,
bytes
);
}
/**
* Converts a string in dotted-decimal notation (x.x.x.x) into
* an IPv4 address.
*
* @param address a string representing an IP address, e.g. "10.0.0.1"
* @return an IP address
*/
public
static
IPAddress
valueOf
(
String
address
)
{
final
String
[]
parts
=
address
.
split
(
"."
);
if
(
parts
.
length
!=
INET_LEN
)
{
throw
new
IllegalArgumentException
(
"Malformed IP address string; "
+
"Addres must have four decimal values separated by dots (.)"
);
}
final
byte
[]
bytes
=
new
byte
[
INET_LEN
];
for
(
int
i
=
0
;
i
<
INET_LEN
;
i
++)
{
bytes
[
i
]
=
Byte
.
parseByte
(
parts
[
i
],
10
);
}
return
new
IPAddress
(
Version
.
INET
,
bytes
);
}
/**
* Returns the IP version of this address.
*
* @return the version
*/
public
Version
version
()
{
return
this
.
version
;
}
/**
* Returns the IP address as a byte array.
*
* @return a byte array
*/
public
byte
[]
toOctets
()
{
return
Arrays
.
copyOf
(
this
.
octets
,
INET_LEN
);
}
public
int
toInt
()
{
int
address
=
((
octets
[
0
]
<<
24
)
|
(
octets
[
1
]
<<
16
)
|
(
octets
[
2
]
<<
8
)
|
(
octets
[
3
]
<<
0
));
return
address
;
}
@Override
public
String
toString
()
{
final
StringBuilder
builder
=
new
StringBuilder
();
for
(
final
byte
b
:
this
.
octets
)
{
if
(
builder
.
length
()
>
0
)
{
builder
.
append
(
"."
);
}
builder
.
append
(
String
.
format
(
"%02d"
,
b
));
}
return
builder
.
toString
();
}
@Override
public
int
hashCode
()
{
return
octets
.
hashCode
();
}
@Override
public
boolean
equals
(
Object
obj
)
{
if
(
this
==
obj
)
{
return
true
;
}
if
(
obj
instanceof
IPAddress
)
{
IPAddress
other
=
(
IPAddress
)
obj
;
if
(!(
this
.
version
.
equals
(
other
.
version
)))
{
return
false
;
}
if
(!(
Arrays
.
equals
(
this
.
octets
,
other
.
octets
)))
{
return
false
;
}
}
return
true
;
}
}
utils/misc/src/main/java/org/onlab/packet/VLANID.java
0 → 100644
View file @
c6ed809
package
org
.
onlab
.
packet
;
/**
* Representation of a VLAN ID.
*/
public
class
VLANID
{
// A VLAN ID is 12 bits, short is close
private
final
short
value
;
public
VLANID
(
short
value
)
{
this
.
value
=
value
;
}
public
short
toShort
()
{
return
this
.
value
;
}
@Override
public
boolean
equals
(
Object
obj
)
{
if
(
this
==
obj
)
{
return
true
;
}
if
(
obj
instanceof
VLANID
)
{
return
true
;
}
VLANID
other
=
(
VLANID
)
obj
;
if
(
this
.
value
==
other
.
value
)
{
return
true
;
}
return
false
;
}
@Override
public
int
hashCode
()
{
return
this
.
value
;
}
}
Please
register
or
login
to post a comment