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-30 16:04:53 -0700
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
50c7bb71669389f6562637cc2fc41d62698af87d
50c7bb71
2 parents
2ac1b82f
2befc661
Merge remote-tracking branch 'origin/master'
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
104 additions
and
86 deletions
apps/config/src/main/java/org/onlab/onos/config/NetworkConfigReader.java
apps/sdnip/src/main/java/org/onlab/onos/sdnip/RouteEntry.java
apps/sdnip/src/test/java/org/onlab/onos/sdnip/bgp/TestBgpPeerChannelHandler.java
core/api/src/main/java/org/onlab/onos/net/flow/DefaultTrafficTreatment.java
core/api/src/main/java/org/onlab/onos/net/flow/TrafficTreatment.java
core/api/src/main/java/org/onlab/onos/net/flow/instructions/Instructions.java
core/api/src/main/java/org/onlab/onos/net/flow/instructions/L3ModificationInstruction.java
core/net/src/main/java/org/onlab/onos/net/device/impl/DeviceManager.java
core/store/dist/src/main/java/org/onlab/onos/store/intent/impl/DistributedIntentStore.java
core/store/serializers/src/main/java/org/onlab/onos/store/serializers/IpPrefixSerializer.java
providers/openflow/flow/src/main/java/org/onlab/onos/provider/of/flow/impl/FlowEntryBuilder.java
providers/openflow/flow/src/main/java/org/onlab/onos/provider/of/flow/impl/FlowModBuilder.java
utils/misc/src/main/java/org/onlab/packet/IpAddress.java
utils/misc/src/main/java/org/onlab/packet/IpPrefix.java
utils/misc/src/main/java/org/onlab/util/KryoNamespace.java
utils/misc/src/test/java/org/onlab/packet/IpPrefixTest.java
apps/config/src/main/java/org/onlab/onos/config/NetworkConfigReader.java
View file @
50c7bb7
...
...
@@ -36,7 +36,6 @@ import org.onlab.onos.net.host.InterfaceIpAddress;
import
org.onlab.onos.net.host.PortAddresses
;
import
org.onlab.packet.IpAddress
;
import
org.onlab.packet.IpPrefix
;
import
org.onlab.packet.Ip4Prefix
;
import
org.onlab.packet.MacAddress
;
import
org.slf4j.Logger
;
...
...
@@ -81,12 +80,8 @@ public class NetworkConfigReader {
if
(
splits
.
length
!=
2
)
{
throw
new
IllegalArgumentException
(
"Invalid IP address and prefix length format"
);
}
//
// TODO: For now we need Ip4Prefix to mask-out the
// subnet address.
//
Ip4Prefix
subnet4
=
new
Ip4Prefix
(
strIp
);
IpPrefix
subnet
=
IpPrefix
.
valueOf
(
subnet4
.
toString
());
// NOTE: IpPrefix will mask-out the bits after the prefix length.
IpPrefix
subnet
=
IpPrefix
.
valueOf
(
strIp
);
IpAddress
addr
=
IpAddress
.
valueOf
(
splits
[
0
]);
InterfaceIpAddress
ia
=
new
InterfaceIpAddress
(
addr
,
subnet
);
...
...
apps/sdnip/src/main/java/org/onlab/onos/sdnip/RouteEntry.java
View file @
50c7bb7
...
...
@@ -73,7 +73,7 @@ public class RouteEntry {
}
StringBuilder
result
=
new
StringBuilder
(
ip4Prefix
.
prefixLength
());
long
value
=
ip4Prefix
.
toInt
()
;
long
value
=
ip4Prefix
.
address
().
toInt
()
&
0xffffffff
L
;
for
(
int
i
=
0
;
i
<
ip4Prefix
.
prefixLength
();
i
++)
{
long
mask
=
1
<<
(
IpPrefix
.
MAX_INET_MASK_LENGTH
-
1
-
i
);
result
.
append
(((
value
&
mask
)
==
0
)
?
"0"
:
"1"
);
...
...
apps/sdnip/src/test/java/org/onlab/onos/sdnip/bgp/TestBgpPeerChannelHandler.java
View file @
50c7bb7
...
...
@@ -188,7 +188,7 @@ class TestBgpPeerChannelHandler extends SimpleChannelHandler {
int
prefixBytelen
=
(
prefixBitlen
+
7
)
/
8
;
// Round-up
message
.
writeByte
(
prefixBitlen
);
IpAddress
address
=
prefix
.
toIpA
ddress
();
IpAddress
address
=
prefix
.
a
ddress
();
long
value
=
address
.
toInt
()
&
0xffffffff
L
;
for
(
int
i
=
0
;
i
<
IpAddress
.
INET_BYTE_LENGTH
;
i
++)
{
if
(
prefixBytelen
--
==
0
)
{
...
...
core/api/src/main/java/org/onlab/onos/net/flow/DefaultTrafficTreatment.java
View file @
50c7bb7
...
...
@@ -22,7 +22,7 @@ import java.util.Objects;
import
org.onlab.onos.net.PortNumber
;
import
org.onlab.onos.net.flow.instructions.Instruction
;
import
org.onlab.onos.net.flow.instructions.Instructions
;
import
org.onlab.packet.Ip
Prefix
;
import
org.onlab.packet.Ip
Address
;
import
org.onlab.packet.MacAddress
;
import
org.onlab.packet.VlanId
;
...
...
@@ -181,12 +181,12 @@ public final class DefaultTrafficTreatment implements TrafficTreatment {
}
@Override
public
Builder
setIpSrc
(
Ip
Prefix
addr
)
{
public
Builder
setIpSrc
(
Ip
Address
addr
)
{
return
add
(
Instructions
.
modL3Src
(
addr
));
}
@Override
public
Builder
setIpDst
(
Ip
Prefix
addr
)
{
public
Builder
setIpDst
(
Ip
Address
addr
)
{
return
add
(
Instructions
.
modL3Dst
(
addr
));
}
...
...
core/api/src/main/java/org/onlab/onos/net/flow/TrafficTreatment.java
View file @
50c7bb7
...
...
@@ -19,7 +19,7 @@ import java.util.List;
import
org.onlab.onos.net.PortNumber
;
import
org.onlab.onos.net.flow.instructions.Instruction
;
import
org.onlab.packet.Ip
Prefix
;
import
org.onlab.packet.Ip
Address
;
import
org.onlab.packet.MacAddress
;
import
org.onlab.packet.VlanId
;
...
...
@@ -92,14 +92,14 @@ public interface TrafficTreatment {
* @param addr an ip
* @return a treatment builder
*/
public
Builder
setIpSrc
(
Ip
Prefix
addr
);
public
Builder
setIpSrc
(
Ip
Address
addr
);
/**
* Sets the dst l3 address.
* @param addr an ip
* @return a treatment builder
*/
public
Builder
setIpDst
(
Ip
Prefix
addr
);
public
Builder
setIpDst
(
Ip
Address
addr
);
/**
* Sets the optical channel ID or lambda.
...
...
core/api/src/main/java/org/onlab/onos/net/flow/instructions/Instructions.java
View file @
50c7bb7
...
...
@@ -27,7 +27,7 @@ import org.onlab.onos.net.flow.instructions.L2ModificationInstruction.L2SubType;
import
org.onlab.onos.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction
;
import
org.onlab.onos.net.flow.instructions.L3ModificationInstruction.L3SubType
;
import
org.onlab.onos.net.flow.instructions.L3ModificationInstruction.ModIPInstruction
;
import
org.onlab.packet.Ip
Prefix
;
import
org.onlab.packet.Ip
Address
;
import
org.onlab.packet.MacAddress
;
import
org.onlab.packet.VlanId
;
...
...
@@ -115,7 +115,7 @@ public final class Instructions {
* @param addr the ip address to modify to.
* @return a L3 modification
*/
public
static
L3ModificationInstruction
modL3Src
(
Ip
Prefix
addr
)
{
public
static
L3ModificationInstruction
modL3Src
(
Ip
Address
addr
)
{
checkNotNull
(
addr
,
"Src l3 address cannot be null"
);
return
new
ModIPInstruction
(
L3SubType
.
IP_SRC
,
addr
);
}
...
...
@@ -125,7 +125,7 @@ public final class Instructions {
* @param addr the ip address to modify to.
* @return a L3 modification
*/
public
static
L3ModificationInstruction
modL3Dst
(
Ip
Prefix
addr
)
{
public
static
L3ModificationInstruction
modL3Dst
(
Ip
Address
addr
)
{
checkNotNull
(
addr
,
"Dst l3 address cannot be null"
);
return
new
ModIPInstruction
(
L3SubType
.
IP_DST
,
addr
);
}
...
...
core/api/src/main/java/org/onlab/onos/net/flow/instructions/L3ModificationInstruction.java
View file @
50c7bb7
...
...
@@ -19,7 +19,7 @@ import static com.google.common.base.MoreObjects.toStringHelper;
import
java.util.Objects
;
import
org.onlab.packet.Ip
Prefix
;
import
org.onlab.packet.Ip
Address
;
/**
* Abstraction of a single traffic treatment step.
...
...
@@ -60,9 +60,9 @@ public abstract class L3ModificationInstruction implements Instruction {
public
static
final
class
ModIPInstruction
extends
L3ModificationInstruction
{
private
final
L3SubType
subtype
;
private
final
Ip
Prefix
ip
;
private
final
Ip
Address
ip
;
public
ModIPInstruction
(
L3SubType
subType
,
Ip
Prefix
addr
)
{
public
ModIPInstruction
(
L3SubType
subType
,
Ip
Address
addr
)
{
this
.
subtype
=
subType
;
this
.
ip
=
addr
;
...
...
@@ -73,7 +73,7 @@ public abstract class L3ModificationInstruction implements Instruction {
return
this
.
subtype
;
}
public
Ip
Prefix
ip
()
{
public
Ip
Address
ip
()
{
return
this
.
ip
;
}
...
...
core/net/src/main/java/org/onlab/onos/net/device/impl/DeviceManager.java
View file @
50c7bb7
...
...
@@ -254,8 +254,7 @@ public class DeviceManager
// }
return
;
}
MastershipTerm
term
=
mastershipService
.
requestTermService
()
.
getMastershipTerm
(
deviceId
);
MastershipTerm
term
=
termService
.
getMastershipTerm
(
deviceId
);
final
NodeId
myNodeId
=
clusterService
.
getLocalNode
().
id
();
if
(!
myNodeId
.
equals
(
term
.
master
()))
{
...
...
core/store/dist/src/main/java/org/onlab/onos/store/intent/impl/DistributedIntentStore.java
View file @
50c7bb7
...
...
@@ -30,6 +30,9 @@ import org.onlab.onos.net.intent.IntentStore;
import
org.onlab.onos.net.intent.IntentStoreDelegate
;
import
org.onlab.onos.store.hz.AbstractHazelcastStore
;
import
org.onlab.onos.store.hz.SMap
;
import
org.onlab.onos.store.serializers.KryoNamespaces
;
import
org.onlab.onos.store.serializers.KryoSerializer
;
import
org.onlab.util.KryoNamespace
;
import
org.slf4j.Logger
;
import
java.util.List
;
...
...
@@ -61,9 +64,21 @@ public class DistributedIntentStore
@Activate
public
void
activate
()
{
// FIXME: We need a way to add serializer for intents which has been plugged-in.
//
TODO:
As a short term workaround, relax Kryo config to
//
registrationRequired=false?
// As a short term workaround, relax Kryo config to
//
registrationRequired=false
super
.
activate
();
super
.
serializer
=
new
KryoSerializer
()
{
@Override
protected
void
setupKryoPool
()
{
serializerPool
=
KryoNamespace
.
newBuilder
()
.
setRegistrationRequired
(
false
)
.
register
(
KryoNamespaces
.
API
)
.
build
()
.
populate
(
1
);
}
};
// TODO: enable near cache, allow read from backup for this IMap
IMap
<
byte
[],
byte
[]>
rawIntents
=
super
.
theInstance
.
getMap
(
"intents"
);
...
...
core/store/serializers/src/main/java/org/onlab/onos/store/serializers/IpPrefixSerializer.java
View file @
50c7bb7
...
...
@@ -38,7 +38,7 @@ public final class IpPrefixSerializer extends Serializer<IpPrefix> {
@Override
public
void
write
(
Kryo
kryo
,
Output
output
,
IpPrefix
object
)
{
byte
[]
octs
=
object
.
toOctets
();
byte
[]
octs
=
object
.
address
().
toOctets
();
output
.
writeInt
(
octs
.
length
);
output
.
writeBytes
(
octs
);
output
.
writeInt
(
object
.
prefixLength
());
...
...
providers/openflow/flow/src/main/java/org/onlab/onos/provider/of/flow/impl/FlowEntryBuilder.java
View file @
50c7bb7
...
...
@@ -31,6 +31,7 @@ import org.onlab.onos.net.flow.FlowRule;
import
org.onlab.onos.net.flow.TrafficSelector
;
import
org.onlab.onos.net.flow.TrafficTreatment
;
import
org.onlab.onos.openflow.controller.Dpid
;
import
org.onlab.packet.IpAddress
;
import
org.onlab.packet.IpPrefix
;
import
org.onlab.packet.MacAddress
;
import
org.onlab.packet.VlanId
;
...
...
@@ -167,24 +168,12 @@ public class FlowEntryBuilder {
case
SET_NW_DST:
OFActionSetNwDst
nwdst
=
(
OFActionSetNwDst
)
act
;
IPv4Address
di
=
nwdst
.
getNwAddr
();
if
(
di
.
isCidrMask
())
{
builder
.
setIpDst
(
IpPrefix
.
valueOf
(
di
.
getInt
(),
di
.
asCidrMaskLength
()));
}
else
{
builder
.
setIpDst
(
IpPrefix
.
valueOf
(
di
.
getInt
(),
IpPrefix
.
MAX_INET_MASK_LENGTH
));
}
builder
.
setIpDst
(
IpAddress
.
valueOf
(
di
.
getInt
()));
break
;
case
SET_NW_SRC:
OFActionSetNwSrc
nwsrc
=
(
OFActionSetNwSrc
)
act
;
IPv4Address
si
=
nwsrc
.
getNwAddr
();
if
(
si
.
isCidrMask
())
{
builder
.
setIpSrc
(
IpPrefix
.
valueOf
(
si
.
getInt
(),
si
.
asCidrMaskLength
()));
}
else
{
builder
.
setIpSrc
(
IpPrefix
.
valueOf
(
si
.
getInt
(),
IpPrefix
.
MAX_INET_MASK_LENGTH
));
}
builder
.
setIpSrc
(
IpAddress
.
valueOf
(
si
.
getInt
()));
break
;
case
EXPERIMENTER:
OFActionExperimenter
exp
=
(
OFActionExperimenter
)
act
;
...
...
providers/openflow/flow/src/main/java/org/onlab/onos/provider/of/flow/impl/FlowModBuilder.java
View file @
50c7bb7
...
...
@@ -29,6 +29,8 @@ import org.onlab.onos.net.flow.criteria.Criteria.TcpPortCriterion;
import
org.onlab.onos.net.flow.criteria.Criteria.VlanIdCriterion
;
import
org.onlab.onos.net.flow.criteria.Criteria.VlanPcpCriterion
;
import
org.onlab.onos.net.flow.criteria.Criterion
;
import
org.onlab.packet.IpAddress
;
import
org.onlab.packet.IpPrefix
;
import
org.projectfloodlight.openflow.protocol.OFFactory
;
import
org.projectfloodlight.openflow.protocol.OFFlowAdd
;
import
org.projectfloodlight.openflow.protocol.OFFlowDelete
;
...
...
@@ -141,22 +143,30 @@ public abstract class FlowModBuilder {
break
;
case
IPV4_DST:
ip
=
(
IPCriterion
)
c
;
if
(
ip
.
ip
().
isMasked
())
{
Masked
<
IPv4Address
>
maskedIp
=
Masked
.
of
(
IPv4Address
.
of
(
ip
.
ip
().
toInt
()),
IPv4Address
.
of
(
ip
.
ip
().
netmask
().
toInt
()));
if
(
ip
.
ip
().
prefixLength
()
!=
IpPrefix
.
MAX_INET_MASK_LENGTH
)
{
IpAddress
maskAddr
=
IpAddress
.
makeMaskPrefix
(
ip
.
ip
().
prefixLength
());
Masked
<
IPv4Address
>
maskedIp
=
Masked
.
of
(
IPv4Address
.
of
(
ip
.
ip
().
address
().
toInt
()),
IPv4Address
.
of
(
maskAddr
.
toInt
()));
mBuilder
.
setMasked
(
MatchField
.
IPV4_DST
,
maskedIp
);
}
else
{
mBuilder
.
setExact
(
MatchField
.
IPV4_DST
,
IPv4Address
.
of
(
ip
.
ip
().
toInt
()));
mBuilder
.
setExact
(
MatchField
.
IPV4_DST
,
IPv4Address
.
of
(
ip
.
ip
().
address
().
toInt
()));
}
break
;
case
IPV4_SRC:
ip
=
(
IPCriterion
)
c
;
if
(
ip
.
ip
().
isMasked
())
{
Masked
<
IPv4Address
>
maskedIp
=
Masked
.
of
(
IPv4Address
.
of
(
ip
.
ip
().
toInt
()),
IPv4Address
.
of
(
ip
.
ip
().
netmask
().
toInt
()));
if
(
ip
.
ip
().
prefixLength
()
!=
IpPrefix
.
MAX_INET_MASK_LENGTH
)
{
IpAddress
maskAddr
=
IpAddress
.
makeMaskPrefix
(
ip
.
ip
().
prefixLength
());
Masked
<
IPv4Address
>
maskedIp
=
Masked
.
of
(
IPv4Address
.
of
(
ip
.
ip
().
address
().
toInt
()),
IPv4Address
.
of
(
maskAddr
.
toInt
()));
mBuilder
.
setMasked
(
MatchField
.
IPV4_SRC
,
maskedIp
);
}
else
{
mBuilder
.
setExact
(
MatchField
.
IPV4_SRC
,
IPv4Address
.
of
(
ip
.
ip
().
toInt
()));
mBuilder
.
setExact
(
MatchField
.
IPV4_SRC
,
IPv4Address
.
of
(
ip
.
ip
().
address
().
toInt
()));
}
break
;
case
IP_PROTO:
...
...
utils/misc/src/main/java/org/onlab/packet/IpAddress.java
View file @
50c7bb7
...
...
@@ -21,7 +21,8 @@ import java.util.Objects;
import
static
com
.
google
.
common
.
base
.
Preconditions
.
checkNotNull
;
/**
* A class representing an IPv4 address.
* A class representing an IP address.
* TODO: Add support for IPv6 as well.
*/
public
final
class
IpAddress
implements
Comparable
<
IpAddress
>
{
// IP Versions
...
...
@@ -44,8 +45,6 @@ public final class IpAddress implements Comparable<IpAddress> {
* @param value the IP address value
*/
private
IpAddress
(
Version
version
,
byte
[]
value
)
{
checkNotNull
(
value
);
this
.
version
=
version
;
this
.
octets
=
Arrays
.
copyOf
(
value
,
INET_BYTE_LENGTH
);
}
...
...
@@ -53,7 +52,7 @@ public final class IpAddress implements Comparable<IpAddress> {
/**
* Converts an integer into an IPv4 address.
*
* @param value an integer representing an IPv4 value
* @param value an integer representing an IPv4
address
value
* @return an IP address
*/
public
static
IpAddress
valueOf
(
int
value
)
{
...
...
@@ -70,6 +69,7 @@ public final class IpAddress implements Comparable<IpAddress> {
* @return an IP address
*/
public
static
IpAddress
valueOf
(
byte
[]
value
)
{
checkNotNull
(
value
);
return
new
IpAddress
(
Version
.
INET
,
value
);
}
...
...
@@ -106,13 +106,13 @@ public final class IpAddress implements Comparable<IpAddress> {
/**
* Converts a dotted-decimal string (x.x.x.x) into an IPv4 address.
*
* @param address a
IP address in string form, e.g. "10.0.0.1".
* @param address a
n IP address in string form, e.g. "10.0.0.1"
* @return an IP address
*/
public
static
IpAddress
valueOf
(
String
address
)
{
final
String
[]
net
=
address
.
split
(
"\\."
);
if
(
net
.
length
!=
INET_BYTE_LENGTH
)
{
String
msg
=
"Malformed IPv4 address string
;
"
+
String
msg
=
"Malformed IPv4 address string
: "
+
address
+
".
"
+
"Address must have four decimal values separated by dots (.)"
;
throw
new
IllegalArgumentException
(
msg
);
}
...
...
@@ -154,20 +154,21 @@ public final class IpAddress implements Comparable<IpAddress> {
/**
* Creates an IP network mask prefix.
*
* @param prefixLen
the length of the mask prefix. Must be in the interval
* [0, 32] for IPv4
* @param prefixLen
gth the length of the mask prefix. Must be in the
*
interval
[0, 32] for IPv4
* @return a new IP address that contains a mask prefix of the
* specified length
*/
public
static
IpAddress
makeMaskPrefix
(
int
prefixLen
)
{
public
static
IpAddress
makeMaskPrefix
(
int
prefixLen
gth
)
{
// Verify the prefix length
if
((
prefixLen
<
0
)
||
(
prefixLen
>
INET_BIT_LENGTH
))
{
final
String
msg
=
"Invalid IPv4 prefix length: "
+
prefixLen
+
if
((
prefixLen
gth
<
0
)
||
(
prefixLength
>
INET_BIT_LENGTH
))
{
final
String
msg
=
"Invalid IPv4 prefix length: "
+
prefixLen
gth
+
". Must be in the interval [0, 32]."
;
throw
new
IllegalArgumentException
(
msg
);
}
long
v
=
(
0xffffffff
L
<<
(
INET_BIT_LENGTH
-
prefixLen
))
&
0xffffffff
L
;
long
v
=
(
0xffffffff
L
<<
(
INET_BIT_LENGTH
-
prefixLength
))
&
0xffffffff
L
;
return
IpAddress
.
valueOf
((
int
)
v
);
}
...
...
@@ -176,14 +177,14 @@ public final class IpAddress implements Comparable<IpAddress> {
* mask length.
*
* @param addr the address to mask
* @param prefixLen
the length of the mask prefix. Must be in the interval
* [0, 32] for IPv4
* @param prefixLen
gth the length of the mask prefix. Must be in the
*
interval
[0, 32] for IPv4
* @return a new IP address that is masked with a mask prefix of the
* specified length
*/
public
static
IpAddress
makeMaskedAddress
(
final
IpAddress
addr
,
int
prefixLen
)
{
IpAddress
mask
=
IpAddress
.
makeMaskPrefix
(
prefixLen
);
int
prefixLen
gth
)
{
IpAddress
mask
=
IpAddress
.
makeMaskPrefix
(
prefixLen
gth
);
byte
[]
net
=
new
byte
[
INET_BYTE_LENGTH
];
// Mask each byte
...
...
@@ -207,7 +208,7 @@ public final class IpAddress implements Comparable<IpAddress> {
@Override
public
boolean
equals
(
Object
obj
)
{
if
(
obj
==
this
)
{
if
(
this
==
obj
)
{
return
true
;
}
if
((
obj
==
null
)
||
(
getClass
()
!=
obj
.
getClass
()))
{
...
...
@@ -221,7 +222,7 @@ public final class IpAddress implements Comparable<IpAddress> {
@Override
/*
* (non-Javadoc)
* format is "x.x.x.x" for IPv4 addresses.
*
The
format is "x.x.x.x" for IPv4 addresses.
*
* @see java.lang.Object#toString()
*/
...
...
utils/misc/src/main/java/org/onlab/packet/IpPrefix.java
View file @
50c7bb7
This diff is collapsed. Click to expand it.
utils/misc/src/main/java/org/onlab/util/KryoNamespace.java
View file @
50c7bb7
...
...
@@ -56,6 +56,7 @@ public final class KryoNamespace implements KryoFactory {
public
static
final
class
Builder
{
private
final
List
<
Pair
<
Class
<?>,
Serializer
<?>>>
types
=
new
ArrayList
<>();
private
boolean
registrationRequired
=
true
;
/**
* Builds a {@link KryoNamespace} instance.
...
...
@@ -63,7 +64,7 @@ public final class KryoNamespace implements KryoFactory {
* @return KryoNamespace
*/
public
KryoNamespace
build
()
{
return
new
KryoNamespace
(
types
);
return
new
KryoNamespace
(
types
,
registrationRequired
);
}
/**
...
...
@@ -101,6 +102,11 @@ public final class KryoNamespace implements KryoFactory {
types
.
addAll
(
pool
.
registeredTypes
);
return
this
;
}
public
Builder
setRegistrationRequired
(
boolean
registrationRequired
)
{
this
.
registrationRequired
=
registrationRequired
;
return
this
;
}
}
/**
...
...
@@ -116,11 +122,11 @@ public final class KryoNamespace implements KryoFactory {
* Creates a Kryo instance pool.
*
* @param registeredTypes types to register
* @param registrationRequired
*/
private
KryoNamespace
(
final
List
<
Pair
<
Class
<?>,
Serializer
<?>>>
registeredTypes
)
{
private
KryoNamespace
(
final
List
<
Pair
<
Class
<?>,
Serializer
<?>>>
registeredTypes
,
boolean
registrationRequired
)
{
this
.
registeredTypes
=
ImmutableList
.
copyOf
(
registeredTypes
);
// always true for now
this
.
registrationRequired
=
true
;
this
.
registrationRequired
=
registrationRequired
;
}
/**
...
...
utils/misc/src/test/java/org/onlab/packet/IpPrefixTest.java
View file @
50c7bb7
...
...
@@ -22,7 +22,7 @@ import static org.junit.Assert.assertTrue;
import
java.util.Arrays
;
import
org.junit.Test
;
import
org.onlab.packet.Ip
Prefix
.Version
;
import
org.onlab.packet.Ip
Address
.Version
;
import
com.google.common.testing.EqualsTester
;
...
...
@@ -30,8 +30,9 @@ public class IpPrefixTest {
private
static
final
byte
[]
BYTES1
=
new
byte
[]
{
0xa
,
0x0
,
0x0
,
0xa
};
private
static
final
byte
[]
BYTES2
=
new
byte
[]
{
0xa
,
0x0
,
0x0
,
0xb
};
private
static
final
int
INTVAL1
=
167772170
;
private
static
final
int
INTVAL2
=
167772171
;
private
static
final
int
INTVAL0
=
0x0a000000
;
private
static
final
int
INTVAL1
=
0x0a00000a
;
private
static
final
int
INTVAL2
=
0x0a00000b
;
private
static
final
String
STRVAL
=
"10.0.0.12/16"
;
private
static
final
int
MASK_LENGTH
=
16
;
...
...
@@ -59,27 +60,29 @@ public class IpPrefixTest {
@Test
public
void
basics
()
{
IpPrefix
ip1
=
IpPrefix
.
valueOf
(
BYTES1
,
MASK_LENGTH
);
final
byte
[]
bytes
=
new
byte
[]
{
0xa
,
0x0
,
0x0
,
0x
a
};
final
byte
[]
bytes
=
new
byte
[]
{
0xa
,
0x0
,
0x0
,
0x
0
};
//check fields
//
check fields
assertEquals
(
"incorrect IP Version"
,
Version
.
INET
,
ip1
.
version
());
assertEquals
(
"incorrect netmask"
,
16
,
ip1
.
prefixLength
());
assertTrue
(
"faulty toOctets()"
,
Arrays
.
equals
(
bytes
,
ip1
.
toOctets
()));
assertEquals
(
"faulty toInt()"
,
INTVAL1
,
ip1
.
toInt
());
assertEquals
(
"faulty toString()"
,
"10.0.0.10/16"
,
ip1
.
toString
());
assertTrue
(
"faulty toOctets()"
,
Arrays
.
equals
(
bytes
,
ip1
.
address
().
toOctets
()));
assertEquals
(
"faulty toInt()"
,
INTVAL0
,
ip1
.
address
().
toInt
());
assertEquals
(
"faulty toString()"
,
"10.0.0.0/16"
,
ip1
.
toString
());
}
@Test
public
void
netmasks
()
{
// masked
IpPrefix
ip1
=
IpPrefix
.
valueOf
(
BYTES1
,
MASK_LENGTH
);
IpPrefix
host
=
IpPrefix
.
valueOf
(
"0.0.0.10/16"
);
IpPrefix
network
=
IpPrefix
.
valueOf
(
"10.0.0.0/16"
);
assertEquals
(
"incorrect host address"
,
host
,
ip1
.
host
());
assertEquals
(
"incorrect network address"
,
network
,
ip1
.
network
());
assertEquals
(
"incorrect netmask"
,
"255.255.0.0"
,
ip1
.
netmask
().
toString
());
IpPrefix
ip2
=
IpPrefix
.
valueOf
(
"10.0.0.10/16"
);
IpPrefix
ip3
=
IpPrefix
.
valueOf
(
"10.0.0.0/16"
);
assertEquals
(
"incorrect binary masked address"
,
ip1
.
toString
(),
"10.0.0.0/16"
);
assertEquals
(
"incorrect string masked address"
,
ip2
.
toString
(),
"10.0.0.0/16"
);
assertEquals
(
"incorrect network address"
,
ip2
.
toString
(),
"10.0.0.0/16"
);
}
@Test
...
...
Please
register
or
login
to post a comment