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-11 13:09:51 -0700
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
1c7b38e6aa26dc8022293a843880700dd184db22
1c7b38e6
1 parent
e5652756
added IPAddress construct
Change-Id: Idc57a22b568b33503c78254222d52fbfc19b0b72
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
159 additions
and
23 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/impl/SimpleHostManager.java
core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleHostStore.java
utils/misc/src/main/java/org/onlab/packet/IPAddress.java
core/api/src/main/java/org/onlab/onos/net/DefaultHost.java
View file @
1c7b38e
...
...
@@ -8,23 +8,26 @@ 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
;
/**
* A basic implementation of a Host.
*/
public
class
DefaultHost
extends
AbstractElement
implements
Host
{
private
final
MACAddress
mac
;
private
final
short
vlan
;
private
final
HostLocation
location
;
private
final
Set
<
IP
v4
>
ips
;
private
final
Set
<
IP
Address
>
ips
;
public
DefaultHost
(
ProviderId
providerId
,
ElementId
id
,
MACAddress
mac
,
short
vlan
,
HostLocation
loc
,
Set
<
IP
v4
>
ips
)
{
short
vlan
,
HostLocation
loc
,
Set
<
IP
Address
>
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 +41,7 @@ public class DefaultHost extends AbstractElement implements Host {
}
@Override
public
Set
<
IP
v4
>
ipAddresses
()
{
public
Set
<
IP
Address
>
ipAddresses
()
{
return
Collections
.
unmodifiableSet
(
ips
);
}
...
...
core/api/src/main/java/org/onlab/onos/net/Host.java
View file @
1c7b38e
package
org
.
onlab
.
onos
.
net
;
import
org.onlab.packet.IP
v4
;
import
org.onlab.packet.IP
Address
;
import
org.onlab.packet.MACAddress
;
import
java.util.Set
;
...
...
@@ -15,6 +15,7 @@ public interface Host extends Element {
*
* @return host id
*/
@Override
HostId
id
();
/**
...
...
@@ -36,7 +37,7 @@ public interface Host extends Element {
*
* @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 @
1c7b38e
...
...
@@ -6,7 +6,7 @@ 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
com.google.common.collect.ImmutableSet
;
...
...
@@ -16,14 +16,14 @@ public class DefaultHostDescription implements HostDescription {
private
final
MACAddress
mac
;
private
final
short
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
)
{
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
...
...
@@ -42,7 +42,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 @
1c7b38e
...
...
@@ -4,7 +4,7 @@ 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
;
/**
...
...
@@ -38,6 +38,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 @
1c7b38e
...
...
@@ -4,7 +4,7 @@ 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
java.util.Set
;
...
...
@@ -59,7 +59,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/impl/SimpleHostManager.java
View file @
1c7b38e
...
...
@@ -21,7 +21,7 @@ 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.slf4j.Logger
;
...
...
@@ -96,7 +96,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/impl/SimpleHostStore.java
View file @
1c7b38e
...
...
@@ -8,7 +8,7 @@ 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
com.google.common.collect.HashMultimap
;
...
...
@@ -62,7 +62,7 @@ public class SimpleHostStore {
descr
.
vlan
(),
descr
.
location
(),
descr
.
ipAddresses
());
synchronized
(
this
)
{
synchronized
(
this
)
{
hosts
.
put
(
hostId
,
newhost
);
locations
.
put
(
descr
.
location
(),
newhost
);
}
...
...
@@ -104,7 +104,7 @@ public class SimpleHostStore {
* @return remove even or null if host was not found
*/
HostEvent
removeHost
(
HostId
hostId
)
{
synchronized
(
this
)
{
synchronized
(
this
)
{
Host
host
=
hosts
.
remove
(
hostId
);
if
(
host
!=
null
)
{
locations
.
remove
((
host
.
location
()),
host
);
...
...
@@ -180,7 +180,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
))
{
...
...
@@ -216,4 +216,4 @@ public class SimpleHostStore {
return
hostset
;
}
}
\ No newline at end of file
}
...
...
utils/misc/src/main/java/org/onlab/packet/IPAddress.java
0 → 100644
View file @
1c7b38e
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 addresses, 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
;
}
}
Please
register
or
login
to post a comment