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-10-09 13:51:01 -0700
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
26673baf39510023ecc02335644cd607440d28ce
26673baf
2 parents
1679e180
58819b4d
Merge remote-tracking branch 'origin/master'
Hide whitespace changes
Inline
Side-by-side
Showing
56 changed files
with
793 additions
and
235 deletions
cli/src/main/java/org/onlab/onos/cli/MastersListCommand.java
cli/src/main/java/org/onlab/onos/cli/net/DeviceRoleCommand.java
core/api/src/main/java/org/onlab/onos/cluster/MastershipAdminService.java → core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipAdminService.java
core/api/src/main/java/org/onlab/onos/cluster/MastershipEvent.java → core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipEvent.java
core/api/src/main/java/org/onlab/onos/cluster/MastershipListener.java → core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipListener.java
core/api/src/main/java/org/onlab/onos/cluster/MastershipService.java → core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipService.java
core/api/src/main/java/org/onlab/onos/cluster/MastershipStore.java → core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipStore.java
core/api/src/main/java/org/onlab/onos/cluster/MastershipStoreDelegate.java → core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipStoreDelegate.java
core/api/src/main/java/org/onlab/onos/cluster/MastershipTerm.java → core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipTerm.java
core/api/src/main/java/org/onlab/onos/cluster/MastershipTermService.java → core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipTermService.java
core/api/src/main/java/org/onlab/onos/net/flow/DefaultTrafficSelector.java
core/api/src/main/java/org/onlab/onos/net/flow/TrafficSelector.java
core/api/src/main/java/org/onlab/onos/net/flow/criteria/Criteria.java
core/api/src/main/java/org/onlab/onos/net/intent/IntentStore.java
core/api/src/main/java/org/onlab/onos/net/intent/package-info.java
core/api/src/main/java/org/onlab/onos/store/AbstractStore.java
core/api/src/main/java/org/onlab/onos/store/ClockProviderService.java
core/store/dist/src/main/java/org/onlab/onos/store/common/impl/Timestamped.java → core/api/src/main/java/org/onlab/onos/store/Timestamped.java
core/store/dist/src/main/java/org/onlab/onos/store/device/impl/VersionedValue.java → core/api/src/main/java/org/onlab/onos/store/VersionedValue.java
core/api/src/test/java/org/onlab/onos/cluster/MastershipServiceAdapter.java
core/api/src/test/java/org/onlab/onos/cluster/MastershipTermTest.java
core/net/src/main/java/org/onlab/onos/cluster/impl/MastershipManager.java
core/net/src/main/java/org/onlab/onos/net/device/impl/DeviceManager.java
core/net/src/main/java/org/onlab/onos/net/proxyarp/impl/ProxyArpManager.java
core/net/src/test/java/org/onlab/onos/cluster/impl/MastershipManagerTest.java
core/net/src/test/java/org/onlab/onos/net/device/impl/DeviceManagerTest.java
core/net/src/test/java/org/onlab/onos/net/proxyarp/impl/ProxyArpManagerTest.java
core/store/dist/src/main/java/org/onlab/onos/store/cluster/messaging/impl/ClusterCommunicationManager.java
core/store/dist/src/main/java/org/onlab/onos/store/serializers/ClusterMessageSerializer.java → core/store/dist/src/main/java/org/onlab/onos/store/cluster/messaging/impl/ClusterMessageSerializer.java
core/store/dist/src/main/java/org/onlab/onos/store/serializers/MessageSubjectSerializer.java → core/store/dist/src/main/java/org/onlab/onos/store/cluster/messaging/impl/MessageSubjectSerializer.java
core/store/dist/src/main/java/org/onlab/onos/store/common/impl/AntiEntropyReply.java
core/store/dist/src/main/java/org/onlab/onos/store/common/impl/MastershipBasedTimestamp.java → core/store/dist/src/main/java/org/onlab/onos/store/common/impl/DeviceMastershipBasedTimestamp.java
core/store/dist/src/main/java/org/onlab/onos/store/serializers/MastershipBasedTimestampSerializer.java → core/store/dist/src/main/java/org/onlab/onos/store/common/impl/MastershipBasedTimestampSerializer.java
core/store/dist/src/main/java/org/onlab/onos/store/device/impl/DeviceAntiEntropyAdvertisement.java
core/store/dist/src/main/java/org/onlab/onos/store/device/impl/DeviceAntiEntropyReply.java
core/store/dist/src/main/java/org/onlab/onos/store/device/impl/DeviceClockManager.java
core/store/dist/src/main/java/org/onlab/onos/store/device/impl/GossipDeviceStore.java
core/store/dist/src/main/java/org/onlab/onos/store/device/impl/InternalDeviceEvent.java
core/store/dist/src/main/java/org/onlab/onos/store/device/impl/InternalDeviceEventSerializer.java
core/store/dist/src/main/java/org/onlab/onos/store/device/impl/InternalPortEvent.java
core/store/dist/src/main/java/org/onlab/onos/store/device/impl/InternalPortEventSerializer.java
core/store/dist/src/main/java/org/onlab/onos/store/device/impl/InternalPortStatusEvent.java
core/store/dist/src/main/java/org/onlab/onos/store/device/impl/InternalPortStatusEventSerializer.java
core/store/dist/src/main/java/org/onlab/onos/store/link/impl/OnosDistributedLinkStore.java
core/store/dist/src/test/java/org/onlab/onos/store/common/impl/MastershipBasedTimestampTest.java
core/store/dist/src/test/java/org/onlab/onos/store/common/impl/TimestampedTest.java
core/store/dist/src/test/java/org/onlab/onos/store/device/impl/GossipDeviceStoreTest.java
core/store/hz/cluster/src/main/java/org/onlab/onos/store/cluster/impl/DistributedMastershipStore.java
core/store/hz/cluster/src/test/java/org/onlab/onos/store/cluster/impl/DistributedMastershipStoreTest.java
core/store/hz/net/src/main/java/org/onlab/onos/store/device/impl/NoOpClockProviderService.java
core/store/serializers/src/main/java/org/onlab/onos/store/serializers/KryoPoolUtil.java
core/store/serializers/src/main/java/org/onlab/onos/store/serializers/MastershipTermSerializer.java
core/store/serializers/src/test/java/org/onlab/onos/store/serializers/KryoSerializerTest.java
core/store/trivial/src/main/java/org/onlab/onos/store/trivial/impl/NoOpClockProviderService.java
core/store/trivial/src/main/java/org/onlab/onos/store/trivial/impl/SimpleMastershipStore.java
core/store/trivial/src/test/java/org/onlab/onos/store/trivial/impl/SimpleMastershipStoreTest.java
cli/src/main/java/org/onlab/onos/cli/MastersListCommand.java
View file @
26673ba
package
org
.
onlab
.
onos
.
cli
;
import
com.google.common.collect.Lists
;
import
org.apache.karaf.shell.commands.Command
;
import
org.onlab.onos.cluster.ClusterService
;
import
org.onlab.onos.cluster.ControllerNode
;
import
org.onlab.onos.cluster.MastershipService
;
import
org.onlab.onos.net.DeviceId
;
import
org.onlab.onos.net.device.DeviceMastershipService
;
import
java.util.Collections
;
import
java.util.List
;
...
...
@@ -22,7 +23,7 @@ public class MastersListCommand extends AbstractShellCommand {
@Override
protected
void
execute
()
{
ClusterService
service
=
get
(
ClusterService
.
class
);
MastershipService
mastershipService
=
get
(
MastershipService
.
class
);
DeviceMastershipService
mastershipService
=
get
(
Device
MastershipService
.
class
);
List
<
ControllerNode
>
nodes
=
newArrayList
(
service
.
getNodes
());
Collections
.
sort
(
nodes
,
Comparators
.
NODE_COMPARATOR
);
ControllerNode
self
=
service
.
getLocalNode
();
...
...
cli/src/main/java/org/onlab/onos/cli/net/DeviceRoleCommand.java
View file @
26673ba
...
...
@@ -3,9 +3,9 @@ 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.cluster.MastershipAdminService
;
import
org.onlab.onos.cluster.NodeId
;
import
org.onlab.onos.net.MastershipRole
;
import
org.onlab.onos.net.device.DeviceMastershipAdminService
;
import
static
org
.
onlab
.
onos
.
net
.
DeviceId
.
deviceId
;
...
...
@@ -30,7 +30,7 @@ public class DeviceRoleCommand extends AbstractShellCommand {
@Override
protected
void
execute
()
{
MastershipAdminService
service
=
get
(
MastershipAdminService
.
class
);
DeviceMastershipAdminService
service
=
get
(
Device
MastershipAdminService
.
class
);
MastershipRole
mastershipRole
=
MastershipRole
.
valueOf
(
role
.
toUpperCase
());
service
.
setRole
(
new
NodeId
(
node
),
deviceId
(
uri
),
mastershipRole
);
}
...
...
core/api/src/main/java/org/onlab/onos/
cluster/
MastershipAdminService.java
→
core/api/src/main/java/org/onlab/onos/
net/device/Device
MastershipAdminService.java
View file @
26673ba
package
org
.
onlab
.
onos
.
cluster
;
package
org
.
onlab
.
onos
.
net
.
device
;
import
org.onlab.onos.cluster.NodeId
;
import
org.onlab.onos.net.DeviceId
;
import
org.onlab.onos.net.MastershipRole
;
/**
* Service for administering the inventory of device masterships.
*/
public
interface
MastershipAdminService
{
public
interface
Device
MastershipAdminService
{
/**
* Applies the current mastership role for the specified device.
...
...
core/api/src/main/java/org/onlab/onos/
cluster/
MastershipEvent.java
→
core/api/src/main/java/org/onlab/onos/
net/device/Device
MastershipEvent.java
View file @
26673ba
package
org
.
onlab
.
onos
.
cluster
;
package
org
.
onlab
.
onos
.
net
.
device
;
import
org.onlab.onos.cluster.NodeId
;
import
org.onlab.onos.event.AbstractEvent
;
import
org.onlab.onos.net.DeviceId
;
/**
* Describes a device mastership event.
*/
public
class
MastershipEvent
extends
AbstractEvent
<
MastershipEvent
.
Type
,
DeviceId
>
{
public
class
DeviceMastershipEvent
extends
AbstractEvent
<
Device
MastershipEvent
.
Type
,
DeviceId
>
{
//do we worry about explicitly setting slaves/equals? probably not,
//to keep it simple
...
...
@@ -30,7 +31,7 @@ public class MastershipEvent extends AbstractEvent<MastershipEvent.Type, DeviceI
* @param device event device subject
* @param master master ID subject
*/
public
MastershipEvent
(
Type
type
,
DeviceId
device
,
NodeId
master
)
{
public
Device
MastershipEvent
(
Type
type
,
DeviceId
device
,
NodeId
master
)
{
super
(
type
,
device
);
this
.
master
=
master
;
}
...
...
@@ -44,7 +45,7 @@ public class MastershipEvent extends AbstractEvent<MastershipEvent.Type, DeviceI
* @param master master ID subject
* @param time occurrence time
*/
public
MastershipEvent
(
Type
type
,
DeviceId
device
,
NodeId
master
,
long
time
)
{
public
Device
MastershipEvent
(
Type
type
,
DeviceId
device
,
NodeId
master
,
long
time
)
{
super
(
type
,
device
,
time
);
this
.
master
=
master
;
}
...
...
core/api/src/main/java/org/onlab/onos/
cluster/
MastershipListener.java
→
core/api/src/main/java/org/onlab/onos/
net/device/Device
MastershipListener.java
View file @
26673ba
package
org
.
onlab
.
onos
.
cluster
;
package
org
.
onlab
.
onos
.
net
.
device
;
import
org.onlab.onos.event.EventListener
;
/**
* Entity capable of receiving device mastership-related events.
*/
public
interface
MastershipListener
extends
EventListener
<
MastershipEvent
>
{
public
interface
DeviceMastershipListener
extends
EventListener
<
Device
MastershipEvent
>
{
}
...
...
core/api/src/main/java/org/onlab/onos/
cluster/
MastershipService.java
→
core/api/src/main/java/org/onlab/onos/
net/device/Device
MastershipService.java
View file @
26673ba
package
org
.
onlab
.
onos
.
cluster
;
package
org
.
onlab
.
onos
.
net
.
device
;
import
java.util.Set
;
import
org.onlab.onos.cluster.NodeId
;
import
org.onlab.onos.net.DeviceId
;
import
org.onlab.onos.net.MastershipRole
;
...
...
@@ -11,7 +12,7 @@ import org.onlab.onos.net.MastershipRole;
* determining mastership, but is not responsible for actually applying it
* to the devices; this falls on the device service.
*/
public
interface
MastershipService
{
public
interface
Device
MastershipService
{
/**
* Returns the role of the local node for the specified device, without
...
...
@@ -62,20 +63,20 @@ public interface MastershipService {
*
* @return the MastershipTermService for this mastership manager
*/
MastershipTermService
requestTermService
();
Device
MastershipTermService
requestTermService
();
/**
* Adds the specified mastership change listener.
*
* @param listener the mastership listener
*/
void
addListener
(
MastershipListener
listener
);
void
addListener
(
Device
MastershipListener
listener
);
/**
* Removes the specified mastership change listener.
*
* @param listener the mastership listener
*/
void
removeListener
(
MastershipListener
listener
);
void
removeListener
(
Device
MastershipListener
listener
);
}
...
...
core/api/src/main/java/org/onlab/onos/
cluster/
MastershipStore.java
→
core/api/src/main/java/org/onlab/onos/
net/device/Device
MastershipStore.java
View file @
26673ba
package
org
.
onlab
.
onos
.
cluster
;
package
org
.
onlab
.
onos
.
net
.
device
;
import
java.util.Set
;
import
org.onlab.onos.cluster.NodeId
;
import
org.onlab.onos.net.DeviceId
;
import
org.onlab.onos.net.MastershipRole
;
import
org.onlab.onos.store.Store
;
...
...
@@ -10,7 +11,7 @@ import org.onlab.onos.store.Store;
* Manages inventory of mastership roles for devices, across controller
* instances; not intended for direct use.
*/
public
interface
MastershipStore
extends
Store
<
MastershipEvent
,
MastershipStoreDelegate
>
{
public
interface
DeviceMastershipStore
extends
Store
<
DeviceMastershipEvent
,
Device
MastershipStoreDelegate
>
{
// three things to map: NodeId, DeviceId, MastershipRole
...
...
@@ -54,7 +55,7 @@ public interface MastershipStore extends Store<MastershipEvent, MastershipStoreD
* @param deviceId device identifier
* @return a mastership event
*/
MastershipEvent
setMaster
(
NodeId
nodeId
,
DeviceId
deviceId
);
Device
MastershipEvent
setMaster
(
NodeId
nodeId
,
DeviceId
deviceId
);
/**
* Returns the current master and number of past mastership hand-offs
...
...
@@ -63,7 +64,7 @@ public interface MastershipStore extends Store<MastershipEvent, MastershipStoreD
* @param deviceId the device identifier
* @return the current master's ID and the term value for device, or null
*/
MastershipTerm
getTermFor
(
DeviceId
deviceId
);
Device
MastershipTerm
getTermFor
(
DeviceId
deviceId
);
/**
* Sets a controller instance's mastership role to STANDBY for a device.
...
...
@@ -74,7 +75,7 @@ public interface MastershipStore extends Store<MastershipEvent, MastershipStoreD
* @param deviceId device to revoke mastership role for
* @return a mastership event
*/
MastershipEvent
setStandby
(
NodeId
nodeId
,
DeviceId
deviceId
);
Device
MastershipEvent
setStandby
(
NodeId
nodeId
,
DeviceId
deviceId
);
/**
* Allows a controller instance to give up its current role for a device.
...
...
@@ -85,6 +86,6 @@ public interface MastershipStore extends Store<MastershipEvent, MastershipStoreD
* @param deviceId device to revoke mastership role for
* @return a mastership event
*/
MastershipEvent
relinquishRole
(
NodeId
nodeId
,
DeviceId
deviceId
);
Device
MastershipEvent
relinquishRole
(
NodeId
nodeId
,
DeviceId
deviceId
);
}
...
...
core/api/src/main/java/org/onlab/onos/
cluster/
MastershipStoreDelegate.java
→
core/api/src/main/java/org/onlab/onos/
net/device/Device
MastershipStoreDelegate.java
View file @
26673ba
package
org
.
onlab
.
onos
.
cluster
;
package
org
.
onlab
.
onos
.
net
.
device
;
import
org.onlab.onos.store.StoreDelegate
;
/**
* Mastership store delegate abstraction.
*
Device
Mastership store delegate abstraction.
*/
public
interface
MastershipStoreDelegate
extends
StoreDelegate
<
MastershipEvent
>
{
public
interface
DeviceMastershipStoreDelegate
extends
StoreDelegate
<
Device
MastershipEvent
>
{
}
...
...
core/api/src/main/java/org/onlab/onos/
cluster/
MastershipTerm.java
→
core/api/src/main/java/org/onlab/onos/
net/device/Device
MastershipTerm.java
View file @
26673ba
package
org
.
onlab
.
onos
.
cluster
;
package
org
.
onlab
.
onos
.
net
.
device
;
import
java.util.Objects
;
public
final
class
MastershipTerm
{
import
org.onlab.onos.cluster.NodeId
;
public
final
class
DeviceMastershipTerm
{
private
final
NodeId
master
;
private
final
int
termNumber
;
private
MastershipTerm
(
NodeId
master
,
int
term
)
{
private
Device
MastershipTerm
(
NodeId
master
,
int
term
)
{
this
.
master
=
master
;
this
.
termNumber
=
term
;
}
public
static
MastershipTerm
of
(
NodeId
master
,
int
term
)
{
return
new
MastershipTerm
(
master
,
term
);
public
static
Device
MastershipTerm
of
(
NodeId
master
,
int
term
)
{
return
new
Device
MastershipTerm
(
master
,
term
);
}
public
NodeId
master
()
{
...
...
@@ -34,8 +36,8 @@ public final class MastershipTerm {
if
(
this
==
other
)
{
return
true
;
}
if
(
other
instanceof
MastershipTerm
)
{
MastershipTerm
that
=
(
MastershipTerm
)
other
;
if
(
other
instanceof
Device
MastershipTerm
)
{
DeviceMastershipTerm
that
=
(
Device
MastershipTerm
)
other
;
if
(!
this
.
master
.
equals
(
that
.
master
))
{
return
false
;
}
...
...
core/api/src/main/java/org/onlab/onos/
cluster/
MastershipTermService.java
→
core/api/src/main/java/org/onlab/onos/
net/device/Device
MastershipTermService.java
View file @
26673ba
package
org
.
onlab
.
onos
.
cluster
;
package
org
.
onlab
.
onos
.
net
.
device
;
import
org.onlab.onos.net.DeviceId
;
...
...
@@ -6,7 +6,7 @@ import org.onlab.onos.net.DeviceId;
/**
* Service to obtain mastership term information.
*/
public
interface
MastershipTermService
{
public
interface
Device
MastershipTermService
{
// TBD: manage/increment per device mastership change
// or increment on any change
...
...
@@ -16,5 +16,5 @@ public interface MastershipTermService {
* @param deviceId the identifier of the device
* @return current master's term.
*/
MastershipTerm
getMastershipTerm
(
DeviceId
deviceId
);
Device
MastershipTerm
getMastershipTerm
(
DeviceId
deviceId
);
}
...
...
core/api/src/main/java/org/onlab/onos/net/flow/DefaultTrafficSelector.java
View file @
26673ba
...
...
@@ -140,6 +140,16 @@ public final class DefaultTrafficSelector implements TrafficSelector {
}
@Override
public
Builder
matchTcpSrc
(
Short
tcpPort
)
{
return
add
(
Criteria
.
matchTcpSrc
(
tcpPort
));
}
@Override
public
Builder
matchTcpDst
(
Short
tcpPort
)
{
return
add
(
Criteria
.
matchTcpDst
(
tcpPort
));
}
@Override
public
TrafficSelector
build
()
{
return
new
DefaultTrafficSelector
(
ImmutableSet
.
copyOf
(
selector
.
values
()));
}
...
...
core/api/src/main/java/org/onlab/onos/net/flow/TrafficSelector.java
View file @
26673ba
...
...
@@ -98,6 +98,20 @@ public interface TrafficSelector {
public
Builder
matchIPDst
(
IpPrefix
ip
);
/**
* Matches a TCP source port number.
* @param tcpPort a TCP source port number
* @return a selection builder
*/
public
Builder
matchTcpSrc
(
Short
tcpPort
);
/**
* Matches a TCP destination port number.
* @param tcpPort a TCP destination port number
* @return a selection builder
*/
public
Builder
matchTcpDst
(
Short
tcpPort
);
/**
* Builds an immutable traffic selector.
*
* @return traffic selector
...
...
core/api/src/main/java/org/onlab/onos/net/flow/criteria/Criteria.java
View file @
26673ba
...
...
@@ -113,6 +113,25 @@ public final class Criteria {
return
new
IPCriterion
(
ip
,
Type
.
IPV4_DST
);
}
/**
* Creates a match on TCP source port field using the specified value.
*
* @param tcpPort
* @return match criterion
*/
public
static
Criterion
matchTcpSrc
(
Short
tcpPort
)
{
return
new
TcpPortCriterion
(
tcpPort
,
Type
.
TCP_SRC
);
}
/**
* Creates a match on TCP destination port field using the specified value.
*
* @param tcpPort
* @return match criterion
*/
public
static
Criterion
matchTcpDst
(
Short
tcpPort
)
{
return
new
TcpPortCriterion
(
tcpPort
,
Type
.
TCP_DST
);
}
/*
* Implementations of criteria.
...
...
@@ -437,4 +456,49 @@ public final class Criteria {
}
public
static
final
class
TcpPortCriterion
implements
Criterion
{
private
final
Short
tcpPort
;
private
final
Type
type
;
public
TcpPortCriterion
(
Short
tcpPort
,
Type
type
)
{
this
.
tcpPort
=
tcpPort
;
this
.
type
=
type
;
}
@Override
public
Type
type
()
{
return
this
.
type
;
}
public
Short
tcpPort
()
{
return
this
.
tcpPort
;
}
@Override
public
String
toString
()
{
return
toStringHelper
(
type
().
toString
())
.
add
(
"tcpPort"
,
tcpPort
).
toString
();
}
@Override
public
int
hashCode
()
{
return
Objects
.
hash
(
tcpPort
,
type
);
}
@Override
public
boolean
equals
(
Object
obj
)
{
if
(
this
==
obj
)
{
return
true
;
}
if
(
obj
instanceof
TcpPortCriterion
)
{
TcpPortCriterion
that
=
(
TcpPortCriterion
)
obj
;
return
Objects
.
equals
(
tcpPort
,
that
.
tcpPort
)
&&
Objects
.
equals
(
type
,
that
.
type
);
}
return
false
;
}
}
}
...
...
core/api/src/main/java/org/onlab/onos/net/intent/IntentStore.java
View file @
26673ba
...
...
@@ -33,6 +33,8 @@ public interface IntentStore extends Store<IntentEvent, IntentStoreDelegate> {
/**
* Returns the number of intents in the store.
*
* @return the number of intents in the store
*/
long
getIntentCount
();
...
...
@@ -44,7 +46,7 @@ public interface IntentStore extends Store<IntentEvent, IntentStoreDelegate> {
Iterable
<
Intent
>
getIntents
();
/**
* Returns the intent with the specified identifer.
* Returns the intent with the specified identif
i
er.
*
* @param intentId intent identification
* @return intent or null if not found
...
...
@@ -94,7 +96,6 @@ public interface IntentStore extends Store<IntentEvent, IntentStoreDelegate> {
* specified original intent.
*
* @param intentId original intent identifier
* @return compiled state transition event
*/
void
removeInstalledIntents
(
IntentId
intentId
);
...
...
core/api/src/main/java/org/onlab/onos/net/intent/package-info.java
View file @
26673ba
...
...
@@ -53,4 +53,4 @@
* while the system determines where to perform the compilation or while it
* performs global recomputation/optimization across all prior intents.
*/
package
org
.
onlab
.
onos
.
net
.
intent
;
\ No newline at end of file
package
org
.
onlab
.
onos
.
net
.
intent
;
...
...
core/api/src/main/java/org/onlab/onos/store/AbstractStore.java
View file @
26673ba
package
org
.
onlab
.
onos
.
store
;
import
java.util.List
;
import
org.onlab.onos.event.Event
;
import
static
com
.
google
.
common
.
base
.
Preconditions
.
checkState
;
...
...
@@ -41,4 +43,15 @@ public class AbstractStore<E extends Event, D extends StoreDelegate<E>>
delegate
.
notify
(
event
);
}
}
/**
* Notifies the delegate with the specified list of events.
*
* @param events list of events to delegate
*/
protected
void
notifyDelegate
(
List
<
E
>
events
)
{
for
(
E
event:
events
)
{
notifyDelegate
(
event
);
}
}
}
...
...
core/api/src/main/java/org/onlab/onos/store/ClockProviderService.java
View file @
26673ba
package
org
.
onlab
.
onos
.
store
;
import
org.onlab.onos.cluster.MastershipTerm
;
import
org.onlab.onos.net.DeviceId
;
import
org.onlab.onos.net.device.DeviceMastershipTerm
;
//TODO: Consider renaming to DeviceClockProviderService?
/**
...
...
@@ -16,5 +16,5 @@ public interface ClockProviderService {
* @param deviceId device identifier.
* @param term mastership term.
*/
public
void
setMastershipTerm
(
DeviceId
deviceId
,
MastershipTerm
term
);
public
void
setMastershipTerm
(
DeviceId
deviceId
,
Device
MastershipTerm
term
);
}
...
...
core/
store/dist/src/main/java/org/onlab/onos/store/common/impl
/Timestamped.java
→
core/
api/src/main/java/org/onlab/onos/store
/Timestamped.java
View file @
26673ba
package
org
.
onlab
.
onos
.
store
.
common
.
impl
;
package
org
.
onlab
.
onos
.
store
;
import
static
com
.
google
.
common
.
base
.
Preconditions
.
checkNotNull
;
import
java.util.Objects
;
import
org.onlab.onos.store.Timestamp
;
import
com.google.common.base.MoreObjects
;
/**
...
...
core/
store/dist/src/main/java/org/onlab/onos/store/device/impl
/VersionedValue.java
→
core/
api/src/main/java/org/onlab/onos/store
/VersionedValue.java
View file @
26673ba
package
org
.
onlab
.
onos
.
store
.
device
.
impl
;
package
org
.
onlab
.
onos
.
store
;
import
java.util.Objects
;
import
org.onlab.onos.store.Timestamp
;
/**
* Wrapper class for a entity that is versioned
* and can either be up or down.
...
...
core/api/src/test/java/org/onlab/onos/cluster/MastershipServiceAdapter.java
View file @
26673ba
...
...
@@ -2,13 +2,16 @@ package org.onlab.onos.cluster;
import
org.onlab.onos.net.DeviceId
;
import
org.onlab.onos.net.MastershipRole
;
import
org.onlab.onos.net.device.DeviceMastershipListener
;
import
org.onlab.onos.net.device.DeviceMastershipService
;
import
org.onlab.onos.net.device.DeviceMastershipTermService
;
import
java.util.Set
;
/**
* Test adapter for mastership service.
*/
public
class
MastershipServiceAdapter
implements
MastershipService
{
public
class
MastershipServiceAdapter
implements
Device
MastershipService
{
@Override
public
MastershipRole
getLocalRole
(
DeviceId
deviceId
)
{
return
null
;
...
...
@@ -34,15 +37,15 @@ public class MastershipServiceAdapter implements MastershipService {
}
@Override
public
void
addListener
(
MastershipListener
listener
)
{
public
void
addListener
(
Device
MastershipListener
listener
)
{
}
@Override
public
void
removeListener
(
MastershipListener
listener
)
{
public
void
removeListener
(
Device
MastershipListener
listener
)
{
}
@Override
public
MastershipTermService
requestTermService
()
{
public
Device
MastershipTermService
requestTermService
()
{
return
null
;
}
}
...
...
core/api/src/test/java/org/onlab/onos/cluster/MastershipTermTest.java
View file @
26673ba
...
...
@@ -3,6 +3,7 @@ package org.onlab.onos.cluster;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
org.junit.Test
;
import
org.onlab.onos.net.device.DeviceMastershipTerm
;
import
com.google.common.testing.EqualsTester
;
...
...
@@ -11,10 +12,10 @@ public class MastershipTermTest {
private
static
final
NodeId
N1
=
new
NodeId
(
"foo"
);
private
static
final
NodeId
N2
=
new
NodeId
(
"bar"
);
private
static
final
MastershipTerm
TERM1
=
MastershipTerm
.
of
(
N1
,
0
);
private
static
final
MastershipTerm
TERM2
=
MastershipTerm
.
of
(
N2
,
1
);
private
static
final
MastershipTerm
TERM3
=
MastershipTerm
.
of
(
N2
,
1
);
private
static
final
MastershipTerm
TERM4
=
MastershipTerm
.
of
(
N1
,
1
);
private
static
final
DeviceMastershipTerm
TERM1
=
Device
MastershipTerm
.
of
(
N1
,
0
);
private
static
final
DeviceMastershipTerm
TERM2
=
Device
MastershipTerm
.
of
(
N2
,
1
);
private
static
final
DeviceMastershipTerm
TERM3
=
Device
MastershipTerm
.
of
(
N2
,
1
);
private
static
final
DeviceMastershipTerm
TERM4
=
Device
MastershipTerm
.
of
(
N1
,
1
);
@Test
public
void
basics
()
{
...
...
@@ -24,7 +25,7 @@ public class MastershipTermTest {
@Test
public
void
testEquality
()
{
new
EqualsTester
().
addEqualityGroup
(
MastershipTerm
.
of
(
N1
,
0
),
TERM1
)
new
EqualsTester
().
addEqualityGroup
(
Device
MastershipTerm
.
of
(
N1
,
0
),
TERM1
)
.
addEqualityGroup
(
TERM2
,
TERM3
)
.
addEqualityGroup
(
TERM4
);
}
...
...
core/net/src/main/java/org/onlab/onos/cluster/impl/MastershipManager.java
View file @
26673ba
...
...
@@ -14,25 +14,25 @@ import org.apache.felix.scr.annotations.Service;
import
org.onlab.onos.cluster.ClusterEvent
;
import
org.onlab.onos.cluster.ClusterEventListener
;
import
org.onlab.onos.cluster.ClusterService
;
import
org.onlab.onos.cluster.MastershipAdminService
;
import
org.onlab.onos.cluster.MastershipEvent
;
import
org.onlab.onos.cluster.MastershipListener
;
import
org.onlab.onos.cluster.MastershipService
;
import
org.onlab.onos.cluster.MastershipStore
;
import
org.onlab.onos.cluster.MastershipStoreDelegate
;
import
org.onlab.onos.cluster.MastershipTerm
;
import
org.onlab.onos.cluster.MastershipTermService
;
import
org.onlab.onos.cluster.NodeId
;
import
org.onlab.onos.event.AbstractListenerRegistry
;
import
org.onlab.onos.event.EventDeliveryService
;
import
org.onlab.onos.net.DeviceId
;
import
org.onlab.onos.net.MastershipRole
;
import
org.onlab.onos.net.device.DeviceMastershipAdminService
;
import
org.onlab.onos.net.device.DeviceMastershipEvent
;
import
org.onlab.onos.net.device.DeviceMastershipListener
;
import
org.onlab.onos.net.device.DeviceMastershipService
;
import
org.onlab.onos.net.device.DeviceMastershipStore
;
import
org.onlab.onos.net.device.DeviceMastershipStoreDelegate
;
import
org.onlab.onos.net.device.DeviceMastershipTerm
;
import
org.onlab.onos.net.device.DeviceMastershipTermService
;
import
org.slf4j.Logger
;
@Component
(
immediate
=
true
)
@Service
public
class
MastershipManager
implements
MastershipService
,
MastershipAdminService
{
implements
DeviceMastershipService
,
Device
MastershipAdminService
{
private
static
final
String
NODE_ID_NULL
=
"Node ID cannot be null"
;
private
static
final
String
DEVICE_ID_NULL
=
"Device ID cannot be null"
;
...
...
@@ -40,13 +40,13 @@ implements MastershipService, MastershipAdminService {
private
final
Logger
log
=
getLogger
(
getClass
());
protected
final
AbstractListenerRegistry
<
MastershipEvent
,
MastershipListener
>
protected
final
AbstractListenerRegistry
<
DeviceMastershipEvent
,
Device
MastershipListener
>
listenerRegistry
=
new
AbstractListenerRegistry
<>();
private
final
MastershipStoreDelegate
delegate
=
new
InternalDelegate
();
private
final
Device
MastershipStoreDelegate
delegate
=
new
InternalDelegate
();
@Reference
(
cardinality
=
ReferenceCardinality
.
MANDATORY_UNARY
)
protected
MastershipStore
store
;
protected
Device
MastershipStore
store
;
@Reference
(
cardinality
=
ReferenceCardinality
.
MANDATORY_UNARY
)
protected
EventDeliveryService
eventDispatcher
;
...
...
@@ -58,7 +58,7 @@ implements MastershipService, MastershipAdminService {
@Activate
public
void
activate
()
{
eventDispatcher
.
addSink
(
MastershipEvent
.
class
,
listenerRegistry
);
eventDispatcher
.
addSink
(
Device
MastershipEvent
.
class
,
listenerRegistry
);
clusterService
.
addListener
(
clusterListener
);
store
.
setDelegate
(
delegate
);
log
.
info
(
"Started"
);
...
...
@@ -66,7 +66,7 @@ implements MastershipService, MastershipAdminService {
@Deactivate
public
void
deactivate
()
{
eventDispatcher
.
removeSink
(
MastershipEvent
.
class
);
eventDispatcher
.
removeSink
(
Device
MastershipEvent
.
class
);
clusterService
.
removeListener
(
clusterListener
);
store
.
unsetDelegate
(
delegate
);
log
.
info
(
"Stopped"
);
...
...
@@ -78,7 +78,7 @@ implements MastershipService, MastershipAdminService {
checkNotNull
(
deviceId
,
DEVICE_ID_NULL
);
checkNotNull
(
role
,
ROLE_NULL
);
MastershipEvent
event
=
null
;
Device
MastershipEvent
event
=
null
;
if
(
role
.
equals
(
MastershipRole
.
MASTER
))
{
event
=
store
.
setMaster
(
nodeId
,
deviceId
);
}
else
{
...
...
@@ -98,7 +98,7 @@ implements MastershipService, MastershipAdminService {
@Override
public
void
relinquishMastership
(
DeviceId
deviceId
)
{
MastershipEvent
event
=
null
;
Device
MastershipEvent
event
=
null
;
event
=
store
.
relinquishRole
(
clusterService
.
getLocalNode
().
id
(),
deviceId
);
...
...
@@ -127,18 +127,18 @@ implements MastershipService, MastershipAdminService {
@Override
public
MastershipTermService
requestTermService
()
{
public
Device
MastershipTermService
requestTermService
()
{
return
new
InternalMastershipTermService
();
}
@Override
public
void
addListener
(
MastershipListener
listener
)
{
public
void
addListener
(
Device
MastershipListener
listener
)
{
checkNotNull
(
listener
);
listenerRegistry
.
addListener
(
listener
);
}
@Override
public
void
removeListener
(
MastershipListener
listener
)
{
public
void
removeListener
(
Device
MastershipListener
listener
)
{
checkNotNull
(
listener
);
listenerRegistry
.
removeListener
(
listener
);
}
...
...
@@ -146,16 +146,16 @@ implements MastershipService, MastershipAdminService {
// FIXME: provide wiring to allow events to be triggered by changes within the store
// Posts the specified event to the local event dispatcher.
private
void
post
(
MastershipEvent
event
)
{
private
void
post
(
Device
MastershipEvent
event
)
{
if
(
event
!=
null
&&
eventDispatcher
!=
null
)
{
eventDispatcher
.
post
(
event
);
}
}
private
class
InternalMastershipTermService
implements
MastershipTermService
{
private
class
InternalMastershipTermService
implements
Device
MastershipTermService
{
@Override
public
MastershipTerm
getMastershipTerm
(
DeviceId
deviceId
)
{
public
Device
MastershipTerm
getMastershipTerm
(
DeviceId
deviceId
)
{
return
store
.
getTermFor
(
deviceId
);
}
...
...
@@ -181,10 +181,10 @@ implements MastershipService, MastershipAdminService {
}
public
class
InternalDelegate
implements
MastershipStoreDelegate
{
public
class
InternalDelegate
implements
Device
MastershipStoreDelegate
{
@Override
public
void
notify
(
MastershipEvent
event
)
{
public
void
notify
(
Device
MastershipEvent
event
)
{
log
.
info
(
"dispatching mastership event {}"
,
event
);
eventDispatcher
.
post
(
event
);
}
...
...
core/net/src/main/java/org/onlab/onos/net/device/impl/DeviceManager.java
View file @
26673ba
...
...
@@ -13,11 +13,6 @@ import org.apache.felix.scr.annotations.Reference;
import
org.apache.felix.scr.annotations.ReferenceCardinality
;
import
org.apache.felix.scr.annotations.Service
;
import
org.onlab.onos.cluster.ClusterService
;
import
org.onlab.onos.cluster.MastershipEvent
;
import
org.onlab.onos.cluster.MastershipListener
;
import
org.onlab.onos.cluster.MastershipService
;
import
org.onlab.onos.cluster.MastershipTermService
;
import
org.onlab.onos.cluster.MastershipTerm
;
import
org.onlab.onos.cluster.NodeId
;
import
org.onlab.onos.event.AbstractListenerRegistry
;
import
org.onlab.onos.event.EventDeliveryService
;
...
...
@@ -36,6 +31,11 @@ import org.onlab.onos.net.device.DeviceProviderService;
import
org.onlab.onos.net.device.DeviceService
;
import
org.onlab.onos.net.device.DeviceStore
;
import
org.onlab.onos.net.device.DeviceStoreDelegate
;
import
org.onlab.onos.net.device.DeviceMastershipEvent
;
import
org.onlab.onos.net.device.DeviceMastershipListener
;
import
org.onlab.onos.net.device.DeviceMastershipService
;
import
org.onlab.onos.net.device.DeviceMastershipTerm
;
import
org.onlab.onos.net.device.DeviceMastershipTermService
;
import
org.onlab.onos.net.device.PortDescription
;
import
org.onlab.onos.net.provider.AbstractProviderRegistry
;
import
org.onlab.onos.net.provider.AbstractProviderService
;
...
...
@@ -64,7 +64,7 @@ public class DeviceManager
private
final
DeviceStoreDelegate
delegate
=
new
InternalStoreDelegate
();
private
final
MastershipListener
mastershipListener
=
new
InternalMastershipListener
();
private
final
Device
MastershipListener
mastershipListener
=
new
InternalMastershipListener
();
@Reference
(
cardinality
=
ReferenceCardinality
.
MANDATORY_UNARY
)
protected
DeviceStore
store
;
...
...
@@ -76,9 +76,9 @@ public class DeviceManager
protected
ClusterService
clusterService
;
@Reference
(
cardinality
=
ReferenceCardinality
.
MANDATORY_UNARY
)
protected
MastershipService
mastershipService
;
protected
Device
MastershipService
mastershipService
;
protected
MastershipTermService
termService
;
protected
Device
MastershipTermService
termService
;
@Reference
(
cardinality
=
ReferenceCardinality
.
MANDATORY_UNARY
)
protected
ClockProviderService
clockProviderService
;
...
...
@@ -209,7 +209,7 @@ public class DeviceManager
return
;
}
MastershipTerm
term
=
mastershipService
.
requestTermService
()
Device
MastershipTerm
term
=
mastershipService
.
requestTermService
()
.
getMastershipTerm
(
deviceId
);
if
(!
term
.
master
().
equals
(
clusterService
.
getLocalNode
().
id
()))
{
// lost mastership after requestRole told this instance was MASTER.
...
...
@@ -320,16 +320,16 @@ public class DeviceManager
}
// Intercepts mastership events
private
class
InternalMastershipListener
implements
MastershipListener
{
private
class
InternalMastershipListener
implements
Device
MastershipListener
{
@Override
public
void
event
(
MastershipEvent
event
)
{
public
void
event
(
Device
MastershipEvent
event
)
{
final
DeviceId
did
=
event
.
subject
();
if
(
isAvailable
(
did
))
{
final
NodeId
myNodeId
=
clusterService
.
getLocalNode
().
id
();
if
(
myNodeId
.
equals
(
event
.
master
()))
{
MastershipTerm
term
=
termService
.
getMastershipTerm
(
did
);
Device
MastershipTerm
term
=
termService
.
getMastershipTerm
(
did
);
if
(
term
.
master
().
equals
(
myNodeId
))
{
// only set the new term if I am the master
...
...
core/net/src/main/java/org/onlab/onos/net/proxyarp/impl/ProxyArpManager.java
View file @
26673ba
...
...
@@ -55,6 +55,7 @@ public class ProxyArpManager implements ProxyArpService {
private
static
final
String
REQUEST_NULL
=
"Arp request cannot be null."
;
private
static
final
String
REQUEST_NOT_ARP
=
"Ethernet frame does not contain ARP request."
;
private
static
final
String
NOT_ARP_REQUEST
=
"ARP is not a request."
;
private
static
final
String
NOT_ARP_REPLY
=
"ARP is not a reply."
;
@Reference
(
cardinality
=
ReferenceCardinality
.
MANDATORY_UNARY
)
protected
HostService
hostService
;
...
...
@@ -141,7 +142,7 @@ public class ProxyArpManager implements ProxyArpService {
checkArgument
(
eth
.
getEtherType
()
==
Ethernet
.
TYPE_ARP
,
REQUEST_NOT_ARP
);
ARP
arp
=
(
ARP
)
eth
.
getPayload
();
checkArgument
(
arp
.
getOpCode
()
==
ARP
.
OP_REPLY
,
NOT_ARP_RE
QUEST
);
checkArgument
(
arp
.
getOpCode
()
==
ARP
.
OP_REPLY
,
NOT_ARP_RE
PLY
);
Host
h
=
hostService
.
getHost
(
HostId
.
hostId
(
eth
.
getDestinationMAC
(),
VlanId
.
vlanId
(
eth
.
getVlanID
())));
...
...
core/net/src/test/java/org/onlab/onos/cluster/impl/MastershipManagerTest.java
View file @
26673ba
...
...
@@ -10,11 +10,11 @@ import org.onlab.onos.cluster.ClusterService;
import
org.onlab.onos.cluster.ControllerNode
;
import
org.onlab.onos.cluster.ControllerNode.State
;
import
org.onlab.onos.cluster.DefaultControllerNode
;
import
org.onlab.onos.cluster.MastershipService
;
import
org.onlab.onos.cluster.MastershipTermService
;
import
org.onlab.onos.cluster.NodeId
;
import
org.onlab.onos.event.impl.TestEventDispatcher
;
import
org.onlab.onos.net.DeviceId
;
import
org.onlab.onos.net.device.DeviceMastershipService
;
import
org.onlab.onos.net.device.DeviceMastershipTermService
;
import
org.onlab.onos.store.trivial.impl.SimpleMastershipStore
;
import
org.onlab.packet.IpPrefix
;
...
...
@@ -34,7 +34,7 @@ public class MastershipManagerTest {
private
static
final
DeviceId
DEV_OTHER
=
DeviceId
.
deviceId
(
"of:2"
);
private
MastershipManager
mgr
;
protected
MastershipService
service
;
protected
Device
MastershipService
service
;
@Before
public
void
setUp
()
{
...
...
@@ -120,7 +120,7 @@ public class MastershipManagerTest {
@Test
public
void
termService
()
{
MastershipTermService
ts
=
mgr
.
requestTermService
();
Device
MastershipTermService
ts
=
mgr
.
requestTermService
();
//term = 0 for both
mgr
.
setRole
(
NID_LOCAL
,
DEV_MASTER
,
MASTER
);
...
...
core/net/src/test/java/org/onlab/onos/net/device/impl/DeviceManagerTest.java
View file @
26673ba
...
...
@@ -11,8 +11,6 @@ import org.onlab.onos.cluster.ClusterService;
import
org.onlab.onos.cluster.ControllerNode
;
import
org.onlab.onos.cluster.DefaultControllerNode
;
import
org.onlab.onos.cluster.MastershipServiceAdapter
;
import
org.onlab.onos.cluster.MastershipTerm
;
import
org.onlab.onos.cluster.MastershipTermService
;
import
org.onlab.onos.cluster.NodeId
;
import
org.onlab.onos.cluster.ControllerNode.State
;
import
org.onlab.onos.event.Event
;
...
...
@@ -32,6 +30,8 @@ import org.onlab.onos.net.device.DeviceProvider;
import
org.onlab.onos.net.device.DeviceProviderRegistry
;
import
org.onlab.onos.net.device.DeviceProviderService
;
import
org.onlab.onos.net.device.DeviceService
;
import
org.onlab.onos.net.device.DeviceMastershipTerm
;
import
org.onlab.onos.net.device.DeviceMastershipTermService
;
import
org.onlab.onos.net.device.PortDescription
;
import
org.onlab.onos.net.provider.AbstractProvider
;
import
org.onlab.onos.net.provider.ProviderId
;
...
...
@@ -290,12 +290,12 @@ public class DeviceManagerTest {
}
@Override
public
MastershipTermService
requestTermService
()
{
return
new
MastershipTermService
()
{
public
Device
MastershipTermService
requestTermService
()
{
return
new
Device
MastershipTermService
()
{
@Override
public
MastershipTerm
getMastershipTerm
(
DeviceId
deviceId
)
{
public
Device
MastershipTerm
getMastershipTerm
(
DeviceId
deviceId
)
{
// FIXME: just returning something not null
return
MastershipTerm
.
of
(
NID_LOCAL
,
1
);
return
Device
MastershipTerm
.
of
(
NID_LOCAL
,
1
);
}
};
}
...
...
@@ -339,7 +339,7 @@ public class DeviceManagerTest {
ClockProviderService
{
@Override
public
void
setMastershipTerm
(
DeviceId
deviceId
,
MastershipTerm
term
)
{
public
void
setMastershipTerm
(
DeviceId
deviceId
,
Device
MastershipTerm
term
)
{
// TODO Auto-generated method stub
}
}
...
...
core/net/src/test/java/org/onlab/onos/net/proxyarp/impl/ProxyArpManagerTest.java
0 → 100644
View file @
26673ba
package
org
.
onlab
.
onos
.
net
.
proxyarp
.
impl
;
import
static
org
.
easymock
.
EasyMock
.
anyObject
;
import
static
org
.
easymock
.
EasyMock
.
createMock
;
import
static
org
.
easymock
.
EasyMock
.
expect
;
import
static
org
.
easymock
.
EasyMock
.
replay
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.List
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.onlab.onos.net.ConnectPoint
;
import
org.onlab.onos.net.DefaultHost
;
import
org.onlab.onos.net.Device
;
import
org.onlab.onos.net.DeviceId
;
import
org.onlab.onos.net.Host
;
import
org.onlab.onos.net.HostId
;
import
org.onlab.onos.net.HostLocation
;
import
org.onlab.onos.net.Link
;
import
org.onlab.onos.net.Port
;
import
org.onlab.onos.net.PortNumber
;
import
org.onlab.onos.net.device.DeviceListener
;
import
org.onlab.onos.net.device.DeviceService
;
import
org.onlab.onos.net.flow.instructions.Instruction
;
import
org.onlab.onos.net.flow.instructions.Instructions.OutputInstruction
;
import
org.onlab.onos.net.host.HostService
;
import
org.onlab.onos.net.link.LinkListener
;
import
org.onlab.onos.net.link.LinkService
;
import
org.onlab.onos.net.packet.OutboundPacket
;
import
org.onlab.onos.net.packet.PacketProcessor
;
import
org.onlab.onos.net.packet.PacketService
;
import
org.onlab.onos.net.provider.ProviderId
;
import
org.onlab.packet.ARP
;
import
org.onlab.packet.Ethernet
;
import
org.onlab.packet.IpPrefix
;
import
org.onlab.packet.MacAddress
;
import
org.onlab.packet.VlanId
;
import
com.google.common.collect.Sets
;
/**
* Tests for the {@link ProxyArpManager} class.
*/
public
class
ProxyArpManagerTest
{
private
static
final
int
NUM_DEVICES
=
4
;
private
static
final
int
NUM_PORTS_PER_DEVICE
=
3
;
private
static
final
int
NUM_FLOOD_PORTS
=
4
;
private
static
final
IpPrefix
IP1
=
IpPrefix
.
valueOf
(
"10.0.0.1/24"
);
private
static
final
IpPrefix
IP2
=
IpPrefix
.
valueOf
(
"10.0.0.2/24"
);
private
static
final
ProviderId
PID
=
new
ProviderId
(
"of"
,
"foo"
);
private
static
final
VlanId
VLAN1
=
VlanId
.
vlanId
((
short
)
1
);
private
static
final
VlanId
VLAN2
=
VlanId
.
vlanId
((
short
)
2
);
private
static
final
MacAddress
MAC1
=
MacAddress
.
valueOf
(
"00:00:11:00:00:01"
);
private
static
final
MacAddress
MAC2
=
MacAddress
.
valueOf
(
"00:00:22:00:00:02"
);
private
static
final
HostId
HID1
=
HostId
.
hostId
(
MAC1
,
VLAN1
);
private
static
final
HostId
HID2
=
HostId
.
hostId
(
MAC2
,
VLAN1
);
private
static
final
DeviceId
DID1
=
getDeviceId
(
1
);
private
static
final
DeviceId
DID2
=
getDeviceId
(
2
);
private
static
final
PortNumber
P1
=
PortNumber
.
portNumber
(
1
);
private
static
final
HostLocation
LOC1
=
new
HostLocation
(
DID1
,
P1
,
123L
);
private
static
final
HostLocation
LOC2
=
new
HostLocation
(
DID2
,
P1
,
123L
);
private
ProxyArpManager
proxyArp
;
private
TestPacketService
packetService
;
private
DeviceService
deviceService
;
private
LinkService
linkService
;
private
HostService
hostService
;
@Before
public
void
setUp
()
throws
Exception
{
proxyArp
=
new
ProxyArpManager
();
packetService
=
new
TestPacketService
();
proxyArp
.
packetService
=
packetService
;
// Create a host service mock here. Must be replayed by tests once the
// expectations have been set up
hostService
=
createMock
(
HostService
.
class
);
proxyArp
.
hostService
=
hostService
;
createTopology
();
proxyArp
.
deviceService
=
deviceService
;
proxyArp
.
linkService
=
linkService
;
proxyArp
.
activate
();
}
/**
* Creates a fake topology to feed into the ARP module.
* <p/>
* The default topology is a unidirectional ring topology. Each switch has
* 3 ports. Ports 2 and 3 have the links to neighbor switches, and port 1
* is free (edge port).
*/
private
void
createTopology
()
{
deviceService
=
createMock
(
DeviceService
.
class
);
linkService
=
createMock
(
LinkService
.
class
);
deviceService
.
addListener
(
anyObject
(
DeviceListener
.
class
));
linkService
.
addListener
(
anyObject
(
LinkListener
.
class
));
createDevices
(
NUM_DEVICES
,
NUM_PORTS_PER_DEVICE
);
createLinks
(
NUM_DEVICES
);
}
/**
* Creates the devices for the fake topology.
*/
private
void
createDevices
(
int
numDevices
,
int
numPorts
)
{
List
<
Device
>
devices
=
new
ArrayList
<>();
for
(
int
i
=
1
;
i
<=
numDevices
;
i
++)
{
DeviceId
devId
=
getDeviceId
(
i
);
Device
device
=
createMock
(
Device
.
class
);
expect
(
device
.
id
()).
andReturn
(
devId
).
anyTimes
();
replay
(
device
);
devices
.
add
(
device
);
List
<
Port
>
ports
=
new
ArrayList
<>();
for
(
int
j
=
1
;
j
<=
numPorts
;
j
++)
{
Port
port
=
createMock
(
Port
.
class
);
expect
(
port
.
number
()).
andReturn
(
PortNumber
.
portNumber
(
j
)).
anyTimes
();
replay
(
port
);
ports
.
add
(
port
);
}
expect
(
deviceService
.
getPorts
(
devId
)).
andReturn
(
ports
);
}
expect
(
deviceService
.
getDevices
()).
andReturn
(
devices
);
replay
(
deviceService
);
}
/**
* Creates the links for the fake topology.
* NB: Only unidirectional links are created, as for this purpose all we
* need is to occupy the ports with some link.
*/
private
void
createLinks
(
int
numDevices
)
{
List
<
Link
>
links
=
new
ArrayList
<
Link
>();
for
(
int
i
=
1
;
i
<=
numDevices
;
i
++)
{
ConnectPoint
src
=
new
ConnectPoint
(
getDeviceId
(
i
),
PortNumber
.
portNumber
(
2
));
ConnectPoint
dst
=
new
ConnectPoint
(
getDeviceId
((
i
+
1
>
numDevices
)
?
1
:
i
+
1
),
PortNumber
.
portNumber
(
3
));
Link
link
=
createMock
(
Link
.
class
);
expect
(
link
.
src
()).
andReturn
(
src
).
anyTimes
();
expect
(
link
.
dst
()).
andReturn
(
dst
).
anyTimes
();
replay
(
link
);
links
.
add
(
link
);
}
expect
(
linkService
.
getLinks
()).
andReturn
(
links
).
anyTimes
();
replay
(
linkService
);
}
/**
* Tests {@link ProxyArpManager#known(IpPrefix)} in the case where the
* IP address is not known.
* Verifies the method returns false.
*/
@Test
public
void
testNotKnown
()
{
expect
(
hostService
.
getHostsByIp
(
IP1
)).
andReturn
(
Collections
.<
Host
>
emptySet
());
replay
(
hostService
);
assertFalse
(
proxyArp
.
known
(
IP1
));
}
/**
* Tests {@link ProxyArpManager#known(IpPrefix)} in the case where the
* IP address is known.
* Verifies the method returns true.
*/
@Test
public
void
testKnown
()
{
Host
host1
=
createMock
(
Host
.
class
);
Host
host2
=
createMock
(
Host
.
class
);
expect
(
hostService
.
getHostsByIp
(
IP1
))
.
andReturn
(
Sets
.
newHashSet
(
host1
,
host2
));
replay
(
hostService
);
assertTrue
(
proxyArp
.
known
(
IP1
));
}
/**
* Tests {@link ProxyArpManager#reply(Ethernet)} in the case where the
* destination host is known.
* Verifies the correct ARP reply is sent out the correct port.
*/
@Test
public
void
testReplyKnown
()
{
Host
replyer
=
new
DefaultHost
(
PID
,
HID1
,
MAC1
,
VLAN1
,
LOC2
,
Collections
.
singleton
(
IP1
));
Host
requestor
=
new
DefaultHost
(
PID
,
HID2
,
MAC2
,
VLAN1
,
LOC1
,
Collections
.
singleton
(
IP2
));
expect
(
hostService
.
getHostsByIp
(
IpPrefix
.
valueOf
(
IP1
.
toOctets
())))
.
andReturn
(
Collections
.
singleton
(
replyer
));
expect
(
hostService
.
getHost
(
HID2
)).
andReturn
(
requestor
);
replay
(
hostService
);
Ethernet
arpRequest
=
buildArp
(
ARP
.
OP_REQUEST
,
MAC2
,
null
,
IP2
,
IP1
);
proxyArp
.
reply
(
arpRequest
);
assertEquals
(
1
,
packetService
.
packets
.
size
());
Ethernet
arpReply
=
buildArp
(
ARP
.
OP_REPLY
,
MAC1
,
MAC2
,
IP1
,
IP2
);
verifyPacketOut
(
arpReply
,
LOC1
,
packetService
.
packets
.
get
(
0
));
}
/**
* Tests {@link ProxyArpManager#reply(Ethernet)} in the case where the
* destination host is not known.
* Verifies the ARP request is flooded out the correct edge ports.
*/
@Test
public
void
testReplyUnknown
()
{
Host
requestor
=
new
DefaultHost
(
PID
,
HID2
,
MAC2
,
VLAN1
,
LOC1
,
Collections
.
singleton
(
IP2
));
expect
(
hostService
.
getHostsByIp
(
IpPrefix
.
valueOf
(
IP1
.
toOctets
())))
.
andReturn
(
Collections
.<
Host
>
emptySet
());
expect
(
hostService
.
getHost
(
HID2
)).
andReturn
(
requestor
);
replay
(
hostService
);
Ethernet
arpRequest
=
buildArp
(
ARP
.
OP_REQUEST
,
MAC2
,
null
,
IP2
,
IP1
);
proxyArp
.
reply
(
arpRequest
);
verifyFlood
(
arpRequest
);
}
/**
* Tests {@link ProxyArpManager#reply(Ethernet)} in the case where the
* destination host is known for that IP address, but is not on the same
* VLAN as the source host.
* Verifies the ARP request is flooded out the correct edge ports.
*/
@Test
public
void
testReplyDifferentVlan
()
{
Host
replyer
=
new
DefaultHost
(
PID
,
HID1
,
MAC1
,
VLAN2
,
LOC2
,
Collections
.
singleton
(
IP1
));
Host
requestor
=
new
DefaultHost
(
PID
,
HID2
,
MAC2
,
VLAN1
,
LOC1
,
Collections
.
singleton
(
IP2
));
expect
(
hostService
.
getHostsByIp
(
IpPrefix
.
valueOf
(
IP1
.
toOctets
())))
.
andReturn
(
Collections
.
singleton
(
replyer
));
expect
(
hostService
.
getHost
(
HID2
)).
andReturn
(
requestor
);
replay
(
hostService
);
Ethernet
arpRequest
=
buildArp
(
ARP
.
OP_REQUEST
,
MAC2
,
null
,
IP2
,
IP1
);
proxyArp
.
reply
(
arpRequest
);
verifyFlood
(
arpRequest
);
}
/**
* Tests {@link ProxyArpManager#forward(Ethernet)} in the case where the
* destination host is known.
* Verifies the correct ARP request is sent out the correct port.
*/
@Test
public
void
testForwardToHost
()
{
Host
host1
=
new
DefaultHost
(
PID
,
HID1
,
MAC1
,
VLAN1
,
LOC1
,
Collections
.
singleton
(
IP1
));
expect
(
hostService
.
getHost
(
HID1
)).
andReturn
(
host1
);
replay
(
hostService
);
Ethernet
arpRequest
=
buildArp
(
ARP
.
OP_REPLY
,
MAC2
,
MAC1
,
IP2
,
IP1
);
proxyArp
.
forward
(
arpRequest
);
assertEquals
(
1
,
packetService
.
packets
.
size
());
OutboundPacket
packet
=
packetService
.
packets
.
get
(
0
);
verifyPacketOut
(
arpRequest
,
LOC1
,
packet
);
}
/**
* Tests {@link ProxyArpManager#forward(Ethernet)} in the case where the
* destination host is not known.
* Verifies the correct ARP request is flooded out the correct edge ports.
*/
@Test
public
void
testForwardFlood
()
{
expect
(
hostService
.
getHost
(
HID1
)).
andReturn
(
null
);
replay
(
hostService
);
Ethernet
arpRequest
=
buildArp
(
ARP
.
OP_REPLY
,
MAC2
,
MAC1
,
IP2
,
IP1
);
proxyArp
.
forward
(
arpRequest
);
verifyFlood
(
arpRequest
);
}
/**
* Verifies that the given packet was flooded out all available edge ports.
*
* @param packet the packet that was expected to be flooded
*/
private
void
verifyFlood
(
Ethernet
packet
)
{
assertEquals
(
NUM_FLOOD_PORTS
,
packetService
.
packets
.
size
());
Collections
.
sort
(
packetService
.
packets
,
new
Comparator
<
OutboundPacket
>()
{
@Override
public
int
compare
(
OutboundPacket
o1
,
OutboundPacket
o2
)
{
return
o1
.
sendThrough
().
uri
().
compareTo
(
o2
.
sendThrough
().
uri
());
}
});
for
(
int
i
=
0
;
i
<
NUM_FLOOD_PORTS
;
i
++)
{
ConnectPoint
cp
=
new
ConnectPoint
(
getDeviceId
(
i
+
1
),
PortNumber
.
portNumber
(
1
));
OutboundPacket
outboundPacket
=
packetService
.
packets
.
get
(
i
);
verifyPacketOut
(
packet
,
cp
,
outboundPacket
);
}
}
/**
* Verifies the given packet was sent out the given port.
*
* @param expected the packet that was expected to be sent
* @param outPort the port the packet was expected to be sent out
* @param actual the actual OutboundPacket to verify
*/
private
void
verifyPacketOut
(
Ethernet
expected
,
ConnectPoint
outPort
,
OutboundPacket
actual
)
{
assertTrue
(
Arrays
.
equals
(
expected
.
serialize
(),
actual
.
data
().
array
()));
assertEquals
(
1
,
actual
.
treatment
().
instructions
().
size
());
assertEquals
(
outPort
.
deviceId
(),
actual
.
sendThrough
());
Instruction
instruction
=
actual
.
treatment
().
instructions
().
get
(
0
);
assertTrue
(
instruction
instanceof
OutputInstruction
);
assertEquals
(
outPort
.
port
(),
((
OutputInstruction
)
instruction
).
port
());
}
/**
* Returns the device ID of the ith device.
*
* @param i device to get the ID of
* @return the device ID
*/
private
static
DeviceId
getDeviceId
(
int
i
)
{
return
DeviceId
.
deviceId
(
""
+
i
);
}
/**
* Builds an ARP packet with the given parameters.
*
* @param opcode opcode of the ARP packet
* @param srcMac source MAC address
* @param dstMac destination MAC address, or null if this is a request
* @param srcIp source IP address
* @param dstIp destination IP address
* @return the ARP packet
*/
private
Ethernet
buildArp
(
short
opcode
,
MacAddress
srcMac
,
MacAddress
dstMac
,
IpPrefix
srcIp
,
IpPrefix
dstIp
)
{
Ethernet
eth
=
new
Ethernet
();
if
(
dstMac
==
null
)
{
eth
.
setDestinationMACAddress
(
MacAddress
.
BROADCAST_MAC
);
}
else
{
eth
.
setDestinationMACAddress
(
dstMac
.
getAddress
());
}
eth
.
setSourceMACAddress
(
srcMac
.
getAddress
());
eth
.
setEtherType
(
Ethernet
.
TYPE_ARP
);
eth
.
setVlanID
(
VLAN1
.
toShort
());
ARP
arp
=
new
ARP
();
arp
.
setOpCode
(
opcode
);
arp
.
setProtocolType
(
ARP
.
PROTO_TYPE_IP
);
arp
.
setHardwareType
(
ARP
.
HW_TYPE_ETHERNET
);
arp
.
setProtocolAddressLength
((
byte
)
IpPrefix
.
INET_LEN
);
arp
.
setHardwareAddressLength
((
byte
)
Ethernet
.
DATALAYER_ADDRESS_LENGTH
);
arp
.
setSenderHardwareAddress
(
srcMac
.
getAddress
());
if
(
dstMac
==
null
)
{
arp
.
setTargetHardwareAddress
(
MacAddress
.
ZERO_MAC_ADDRESS
);
}
else
{
arp
.
setTargetHardwareAddress
(
dstMac
.
getAddress
());
}
arp
.
setSenderProtocolAddress
(
srcIp
.
toOctets
());
arp
.
setTargetProtocolAddress
(
dstIp
.
toOctets
());
eth
.
setPayload
(
arp
);
return
eth
;
}
/**
* Test PacketService implementation that simply stores OutboundPackets
* passed to {@link #emit(OutboundPacket)} for later verification.
*/
class
TestPacketService
implements
PacketService
{
List
<
OutboundPacket
>
packets
=
new
ArrayList
<>();
@Override
public
void
addProcessor
(
PacketProcessor
processor
,
int
priority
)
{
}
@Override
public
void
removeProcessor
(
PacketProcessor
processor
)
{
}
@Override
public
void
emit
(
OutboundPacket
packet
)
{
packets
.
add
(
packet
);
}
}
}
core/store/dist/src/main/java/org/onlab/onos/store/cluster/messaging/impl/ClusterCommunicationManager.java
View file @
26673ba
...
...
@@ -6,6 +6,7 @@ import java.io.IOException;
import
java.util.Set
;
import
java.util.Timer
;
import
java.util.TimerTask
;
import
org.apache.felix.scr.annotations.Activate
;
import
org.apache.felix.scr.annotations.Component
;
import
org.apache.felix.scr.annotations.Deactivate
;
...
...
@@ -23,10 +24,8 @@ import org.onlab.onos.store.cluster.messaging.ClusterCommunicationService;
import
org.onlab.onos.store.cluster.messaging.ClusterMessage
;
import
org.onlab.onos.store.cluster.messaging.ClusterMessageHandler
;
import
org.onlab.onos.store.cluster.messaging.MessageSubject
;
import
org.onlab.onos.store.serializers.ClusterMessageSerializer
;
import
org.onlab.onos.store.serializers.KryoPoolUtil
;
import
org.onlab.onos.store.serializers.KryoSerializer
;
import
org.onlab.onos.store.serializers.MessageSubjectSerializer
;
import
org.onlab.util.KryoPool
;
import
org.onlab.netty.Endpoint
;
import
org.onlab.netty.Message
;
...
...
core/store/dist/src/main/java/org/onlab/onos/store/
serializers
/ClusterMessageSerializer.java
→
core/store/dist/src/main/java/org/onlab/onos/store/
cluster/messaging/impl
/ClusterMessageSerializer.java
View file @
26673ba
package
org
.
onlab
.
onos
.
store
.
serializers
;
package
org
.
onlab
.
onos
.
store
.
cluster
.
messaging
.
impl
;
import
org.onlab.onos.cluster.NodeId
;
import
org.onlab.onos.store.cluster.messaging.ClusterMessage
;
...
...
core/store/dist/src/main/java/org/onlab/onos/store/
serializers
/MessageSubjectSerializer.java
→
core/store/dist/src/main/java/org/onlab/onos/store/
cluster/messaging/impl
/MessageSubjectSerializer.java
View file @
26673ba
package
org
.
onlab
.
onos
.
store
.
serializers
;
package
org
.
onlab
.
onos
.
store
.
cluster
.
messaging
.
impl
;
import
org.onlab.onos.store.cluster.messaging.MessageSubject
;
...
...
core/store/dist/src/main/java/org/onlab/onos/store/common/impl/AntiEntropyReply.java
View file @
26673ba
...
...
@@ -4,7 +4,7 @@ import java.util.Map;
import
java.util.Set
;
import
org.onlab.onos.cluster.NodeId
;
import
org.onlab.onos.store.
device.impl.
VersionedValue
;
import
org.onlab.onos.store.VersionedValue
;
import
com.google.common.collect.ImmutableMap
;
import
com.google.common.collect.ImmutableSet
;
...
...
core/store/dist/src/main/java/org/onlab/onos/store/common/impl/MastershipBasedTimestamp.java
→
core/store/dist/src/main/java/org/onlab/onos/store/common/impl/
Device
MastershipBasedTimestamp.java
View file @
26673ba
...
...
@@ -13,7 +13,7 @@ import com.google.common.collect.ComparisonChain;
* Default implementation of Timestamp.
* TODO: Better documentation.
*/
public
final
class
MastershipBasedTimestamp
implements
Timestamp
{
public
final
class
Device
MastershipBasedTimestamp
implements
Timestamp
{
private
final
int
termNumber
;
private
final
int
sequenceNumber
;
...
...
@@ -24,16 +24,16 @@ public final class MastershipBasedTimestamp implements Timestamp {
* @param termNumber the mastership termNumber
* @param sequenceNumber the sequenceNumber number within the termNumber
*/
public
MastershipBasedTimestamp
(
int
termNumber
,
int
sequenceNumber
)
{
public
Device
MastershipBasedTimestamp
(
int
termNumber
,
int
sequenceNumber
)
{
this
.
termNumber
=
termNumber
;
this
.
sequenceNumber
=
sequenceNumber
;
}
@Override
public
int
compareTo
(
Timestamp
o
)
{
checkArgument
(
o
instanceof
MastershipBasedTimestamp
,
checkArgument
(
o
instanceof
Device
MastershipBasedTimestamp
,
"Must be MastershipBasedTimestamp"
,
o
);
MastershipBasedTimestamp
that
=
(
MastershipBasedTimestamp
)
o
;
DeviceMastershipBasedTimestamp
that
=
(
Device
MastershipBasedTimestamp
)
o
;
return
ComparisonChain
.
start
()
.
compare
(
this
.
termNumber
,
that
.
termNumber
)
...
...
@@ -51,10 +51,10 @@ public final class MastershipBasedTimestamp implements Timestamp {
if
(
this
==
obj
)
{
return
true
;
}
if
(!(
obj
instanceof
MastershipBasedTimestamp
))
{
if
(!(
obj
instanceof
Device
MastershipBasedTimestamp
))
{
return
false
;
}
MastershipBasedTimestamp
that
=
(
MastershipBasedTimestamp
)
obj
;
DeviceMastershipBasedTimestamp
that
=
(
Device
MastershipBasedTimestamp
)
obj
;
return
Objects
.
equals
(
this
.
termNumber
,
that
.
termNumber
)
&&
Objects
.
equals
(
this
.
sequenceNumber
,
that
.
sequenceNumber
);
}
...
...
@@ -87,7 +87,7 @@ public final class MastershipBasedTimestamp implements Timestamp {
// Default constructor for serialization
@Deprecated
protected
MastershipBasedTimestamp
()
{
protected
Device
MastershipBasedTimestamp
()
{
this
.
termNumber
=
-
1
;
this
.
sequenceNumber
=
-
1
;
}
...
...
core/store/dist/src/main/java/org/onlab/onos/store/
serializers
/MastershipBasedTimestampSerializer.java
→
core/store/dist/src/main/java/org/onlab/onos/store/
common/impl
/MastershipBasedTimestampSerializer.java
View file @
26673ba
package
org
.
onlab
.
onos
.
store
.
serializers
;
import
org.onlab.onos.store.common.impl.MastershipBasedTimestamp
;
package
org
.
onlab
.
onos
.
store
.
common
.
impl
;
import
com.esotericsoftware.kryo.Kryo
;
import
com.esotericsoftware.kryo.Serializer
;
...
...
@@ -9,12 +7,12 @@ import com.esotericsoftware.kryo.io.Output;
// To be used if Timestamp ever needs to cross bundle boundary.
/**
* Kryo Serializer for {@link MastershipBasedTimestamp}.
* Kryo Serializer for {@link
Device
MastershipBasedTimestamp}.
*/
public
class
MastershipBasedTimestampSerializer
extends
Serializer
<
MastershipBasedTimestamp
>
{
public
class
MastershipBasedTimestampSerializer
extends
Serializer
<
Device
MastershipBasedTimestamp
>
{
/**
* Creates a serializer for {@link MastershipBasedTimestamp}.
* Creates a serializer for {@link
Device
MastershipBasedTimestamp}.
*/
public
MastershipBasedTimestampSerializer
()
{
// non-null, immutable
...
...
@@ -22,15 +20,15 @@ public class MastershipBasedTimestampSerializer extends Serializer<MastershipBas
}
@Override
public
void
write
(
Kryo
kryo
,
Output
output
,
MastershipBasedTimestamp
object
)
{
public
void
write
(
Kryo
kryo
,
Output
output
,
Device
MastershipBasedTimestamp
object
)
{
output
.
writeInt
(
object
.
termNumber
());
output
.
writeInt
(
object
.
sequenceNumber
());
}
@Override
public
MastershipBasedTimestamp
read
(
Kryo
kryo
,
Input
input
,
Class
<
MastershipBasedTimestamp
>
type
)
{
public
DeviceMastershipBasedTimestamp
read
(
Kryo
kryo
,
Input
input
,
Class
<
Device
MastershipBasedTimestamp
>
type
)
{
final
int
term
=
input
.
readInt
();
final
int
sequence
=
input
.
readInt
();
return
new
MastershipBasedTimestamp
(
term
,
sequence
);
return
new
Device
MastershipBasedTimestamp
(
term
,
sequence
);
}
}
...
...
core/store/dist/src/main/java/org/onlab/onos/store/device/impl/DeviceAntiEntropyAdvertisement.java
View file @
26673ba
...
...
@@ -8,6 +8,7 @@ import org.onlab.onos.cluster.NodeId;
import
org.onlab.onos.net.Device
;
import
org.onlab.onos.net.DeviceId
;
import
org.onlab.onos.store.Timestamp
;
import
org.onlab.onos.store.VersionedValue
;
import
org.onlab.onos.store.common.impl.AntiEntropyAdvertisement
;
// TODO DeviceID needs to be changed to something like (ProviderID, DeviceID)
...
...
core/store/dist/src/main/java/org/onlab/onos/store/device/impl/DeviceAntiEntropyReply.java
View file @
26673ba
...
...
@@ -10,6 +10,7 @@ import org.onlab.onos.cluster.NodeId;
import
org.onlab.onos.net.Device
;
import
org.onlab.onos.net.DeviceId
;
import
org.onlab.onos.store.Timestamp
;
import
org.onlab.onos.store.VersionedValue
;
import
org.onlab.onos.store.common.impl.AntiEntropyReply
;
import
com.google.common.collect.ImmutableMap
;
...
...
core/store/dist/src/main/java/org/onlab/onos/store/device/impl/DeviceClockManager.java
View file @
26673ba
...
...
@@ -10,12 +10,12 @@ import org.apache.felix.scr.annotations.Activate;
import
org.apache.felix.scr.annotations.Component
;
import
org.apache.felix.scr.annotations.Deactivate
;
import
org.apache.felix.scr.annotations.Service
;
import
org.onlab.onos.cluster.MastershipTerm
;
import
org.onlab.onos.net.DeviceId
;
import
org.onlab.onos.net.device.DeviceMastershipTerm
;
import
org.onlab.onos.store.ClockProviderService
;
import
org.onlab.onos.store.ClockService
;
import
org.onlab.onos.store.Timestamp
;
import
org.onlab.onos.store.common.impl.MastershipBasedTimestamp
;
import
org.onlab.onos.store.common.impl.
Device
MastershipBasedTimestamp
;
import
org.slf4j.Logger
;
/**
...
...
@@ -29,7 +29,7 @@ public class DeviceClockManager implements ClockService, ClockProviderService {
// TODO: Implement per device ticker that is reset to 0 at the beginning of a new term.
private
final
AtomicInteger
ticker
=
new
AtomicInteger
(
0
);
private
ConcurrentMap
<
DeviceId
,
MastershipTerm
>
deviceMastershipTerms
=
new
ConcurrentHashMap
<>();
private
ConcurrentMap
<
DeviceId
,
Device
MastershipTerm
>
deviceMastershipTerms
=
new
ConcurrentHashMap
<>();
@Activate
public
void
activate
()
{
...
...
@@ -43,15 +43,15 @@ public class DeviceClockManager implements ClockService, ClockProviderService {
@Override
public
Timestamp
getTimestamp
(
DeviceId
deviceId
)
{
MastershipTerm
term
=
deviceMastershipTerms
.
get
(
deviceId
);
Device
MastershipTerm
term
=
deviceMastershipTerms
.
get
(
deviceId
);
if
(
term
==
null
)
{
throw
new
IllegalStateException
(
"Requesting timestamp for a deviceId without mastership"
);
}
return
new
MastershipBasedTimestamp
(
term
.
termNumber
(),
ticker
.
incrementAndGet
());
return
new
Device
MastershipBasedTimestamp
(
term
.
termNumber
(),
ticker
.
incrementAndGet
());
}
@Override
public
void
setMastershipTerm
(
DeviceId
deviceId
,
MastershipTerm
term
)
{
public
void
setMastershipTerm
(
DeviceId
deviceId
,
Device
MastershipTerm
term
)
{
deviceMastershipTerms
.
put
(
deviceId
,
term
);
}
}
...
...
core/store/dist/src/main/java/org/onlab/onos/store/device/impl/GossipDeviceStore.java
View file @
26673ba
...
...
@@ -35,14 +35,14 @@ import org.onlab.onos.net.provider.ProviderId;
import
org.onlab.onos.store.AbstractStore
;
import
org.onlab.onos.store.ClockService
;
import
org.onlab.onos.store.Timestamp
;
import
org.onlab.onos.store.Timestamped
;
import
org.onlab.onos.store.cluster.messaging.ClusterCommunicationService
;
import
org.onlab.onos.store.cluster.messaging.ClusterMessage
;
import
org.onlab.onos.store.cluster.messaging.ClusterMessageHandler
;
import
org.onlab.onos.store.common.impl.MastershipBasedTimestamp
;
import
org.onlab.onos.store.common.impl.
Timestamped
;
import
org.onlab.onos.store.common.impl.
Device
MastershipBasedTimestamp
;
import
org.onlab.onos.store.common.impl.
MastershipBasedTimestampSerializer
;
import
org.onlab.onos.store.serializers.KryoPoolUtil
;
import
org.onlab.onos.store.serializers.KryoSerializer
;
import
org.onlab.onos.store.serializers.MastershipBasedTimestampSerializer
;
import
org.onlab.util.KryoPool
;
import
org.onlab.util.NewConcurrentHashMap
;
import
org.slf4j.Logger
;
...
...
@@ -125,7 +125,7 @@ public class GossipDeviceStore
.
register
(
InternalPortStatusEvent
.
class
,
new
InternalPortStatusEventSerializer
())
.
register
(
Timestamp
.
class
)
.
register
(
Timestamped
.
class
)
.
register
(
MastershipBasedTimestamp
.
class
,
new
MastershipBasedTimestampSerializer
())
.
register
(
Device
MastershipBasedTimestamp
.
class
,
new
MastershipBasedTimestampSerializer
())
.
build
()
.
populate
(
1
);
}
...
...
@@ -870,6 +870,12 @@ public class GossipDeviceStore
clusterCommunicator
.
broadcast
(
message
);
}
private
void
notifyDelegateIfNotNull
(
DeviceEvent
event
)
{
if
(
event
!=
null
)
{
notifyDelegate
(
event
);
}
}
private
class
InternalDeviceEventListener
implements
ClusterMessageHandler
{
@Override
public
void
handle
(
ClusterMessage
message
)
{
...
...
@@ -881,7 +887,7 @@ public class GossipDeviceStore
DeviceId
deviceId
=
event
.
deviceId
();
Timestamped
<
DeviceDescription
>
deviceDescription
=
event
.
deviceDescription
();
createOrUpdateDeviceInternal
(
providerId
,
deviceId
,
deviceDescription
);
notifyDelegateIfNotNull
(
createOrUpdateDeviceInternal
(
providerId
,
deviceId
,
deviceDescription
)
);
}
}
...
...
@@ -895,7 +901,7 @@ public class GossipDeviceStore
DeviceId
deviceId
=
event
.
deviceId
();
Timestamp
timestamp
=
event
.
timestamp
();
markOfflineInternal
(
deviceId
,
timestamp
);
notifyDelegateIfNotNull
(
markOfflineInternal
(
deviceId
,
timestamp
)
);
}
}
...
...
@@ -909,7 +915,7 @@ public class GossipDeviceStore
DeviceId
deviceId
=
event
.
deviceId
();
Timestamp
timestamp
=
event
.
timestamp
();
removeDeviceInternal
(
deviceId
,
timestamp
);
notifyDelegateIfNotNull
(
removeDeviceInternal
(
deviceId
,
timestamp
)
);
}
}
...
...
@@ -924,7 +930,7 @@ public class GossipDeviceStore
DeviceId
deviceId
=
event
.
deviceId
();
Timestamped
<
List
<
PortDescription
>>
portDescriptions
=
event
.
portDescriptions
();
updatePortsInternal
(
providerId
,
deviceId
,
portDescriptions
);
notifyDelegate
(
updatePortsInternal
(
providerId
,
deviceId
,
portDescriptions
)
);
}
}
...
...
@@ -939,7 +945,7 @@ public class GossipDeviceStore
DeviceId
deviceId
=
event
.
deviceId
();
Timestamped
<
PortDescription
>
portDescription
=
event
.
portDescription
();
updatePortStatusInternal
(
providerId
,
deviceId
,
portDescription
);
notifyDelegateIfNotNull
(
updatePortStatusInternal
(
providerId
,
deviceId
,
portDescription
)
);
}
}
}
...
...
core/store/dist/src/main/java/org/onlab/onos/store/device/impl/InternalDeviceEvent.java
View file @
26673ba
...
...
@@ -3,7 +3,7 @@ package org.onlab.onos.store.device.impl;
import
org.onlab.onos.net.DeviceId
;
import
org.onlab.onos.net.device.DeviceDescription
;
import
org.onlab.onos.net.provider.ProviderId
;
import
org.onlab.onos.store.
common.impl.
Timestamped
;
import
org.onlab.onos.store.Timestamped
;
/**
* Information published by GossipDeviceStore to notify peers of a device
...
...
core/store/dist/src/main/java/org/onlab/onos/store/device/impl/InternalDeviceEventSerializer.java
View file @
26673ba
...
...
@@ -3,7 +3,7 @@ package org.onlab.onos.store.device.impl;
import
org.onlab.onos.net.DeviceId
;
import
org.onlab.onos.net.device.DeviceDescription
;
import
org.onlab.onos.net.provider.ProviderId
;
import
org.onlab.onos.store.
common.impl.
Timestamped
;
import
org.onlab.onos.store.Timestamped
;
import
com.esotericsoftware.kryo.Kryo
;
import
com.esotericsoftware.kryo.Serializer
;
...
...
core/store/dist/src/main/java/org/onlab/onos/store/device/impl/InternalPortEvent.java
View file @
26673ba
...
...
@@ -5,7 +5,7 @@ import java.util.List;
import
org.onlab.onos.net.DeviceId
;
import
org.onlab.onos.net.device.PortDescription
;
import
org.onlab.onos.net.provider.ProviderId
;
import
org.onlab.onos.store.
common.impl.
Timestamped
;
import
org.onlab.onos.store.Timestamped
;
/**
* Information published by GossipDeviceStore to notify peers of a port
...
...
core/store/dist/src/main/java/org/onlab/onos/store/device/impl/InternalPortEventSerializer.java
View file @
26673ba
...
...
@@ -5,7 +5,7 @@ import java.util.List;
import
org.onlab.onos.net.DeviceId
;
import
org.onlab.onos.net.device.PortDescription
;
import
org.onlab.onos.net.provider.ProviderId
;
import
org.onlab.onos.store.
common.impl.
Timestamped
;
import
org.onlab.onos.store.Timestamped
;
import
com.esotericsoftware.kryo.Kryo
;
import
com.esotericsoftware.kryo.Serializer
;
...
...
core/store/dist/src/main/java/org/onlab/onos/store/device/impl/InternalPortStatusEvent.java
View file @
26673ba
...
...
@@ -3,7 +3,7 @@ package org.onlab.onos.store.device.impl;
import
org.onlab.onos.net.DeviceId
;
import
org.onlab.onos.net.device.PortDescription
;
import
org.onlab.onos.net.provider.ProviderId
;
import
org.onlab.onos.store.
common.impl.
Timestamped
;
import
org.onlab.onos.store.Timestamped
;
/**
* Information published by GossipDeviceStore to notify peers of a port
...
...
core/store/dist/src/main/java/org/onlab/onos/store/device/impl/InternalPortStatusEventSerializer.java
View file @
26673ba
...
...
@@ -3,7 +3,7 @@ package org.onlab.onos.store.device.impl;
import
org.onlab.onos.net.DeviceId
;
import
org.onlab.onos.net.device.PortDescription
;
import
org.onlab.onos.net.provider.ProviderId
;
import
org.onlab.onos.store.
common.impl.
Timestamped
;
import
org.onlab.onos.store.Timestamped
;
import
com.esotericsoftware.kryo.Kryo
;
import
com.esotericsoftware.kryo.Serializer
;
...
...
core/store/dist/src/main/java/org/onlab/onos/store/link/impl/OnosDistributedLinkStore.java
View file @
26673ba
...
...
@@ -31,7 +31,7 @@ import org.onlab.onos.net.provider.ProviderId;
import
org.onlab.onos.store.AbstractStore
;
import
org.onlab.onos.store.ClockService
;
import
org.onlab.onos.store.Timestamp
;
import
org.onlab.onos.store.
device.impl.
VersionedValue
;
import
org.onlab.onos.store.VersionedValue
;
import
org.slf4j.Logger
;
import
com.google.common.collect.HashMultimap
;
...
...
core/store/dist/src/test/java/org/onlab/onos/store/common/impl/MastershipBasedTimestampTest.java
View file @
26673ba
...
...
@@ -6,26 +6,25 @@ import java.nio.ByteBuffer;
import
org.junit.Test
;
import
org.onlab.onos.store.Timestamp
;
import
org.onlab.onos.store.serializers.MastershipBasedTimestampSerializer
;
import
org.onlab.util.KryoPool
;
import
com.google.common.testing.EqualsTester
;
/**
* Test of {@link MastershipBasedTimestamp}.
* Test of {@link
Device
MastershipBasedTimestamp}.
*/
public
class
MastershipBasedTimestampTest
{
private
static
final
Timestamp
TS_1_1
=
new
MastershipBasedTimestamp
(
1
,
1
);
private
static
final
Timestamp
TS_1_2
=
new
MastershipBasedTimestamp
(
1
,
2
);
private
static
final
Timestamp
TS_2_1
=
new
MastershipBasedTimestamp
(
2
,
1
);
private
static
final
Timestamp
TS_2_2
=
new
MastershipBasedTimestamp
(
2
,
2
);
private
static
final
Timestamp
TS_1_1
=
new
Device
MastershipBasedTimestamp
(
1
,
1
);
private
static
final
Timestamp
TS_1_2
=
new
Device
MastershipBasedTimestamp
(
1
,
2
);
private
static
final
Timestamp
TS_2_1
=
new
Device
MastershipBasedTimestamp
(
2
,
1
);
private
static
final
Timestamp
TS_2_2
=
new
Device
MastershipBasedTimestamp
(
2
,
2
);
@Test
public
final
void
testBasic
()
{
final
int
termNumber
=
5
;
final
int
sequenceNumber
=
6
;
MastershipBasedTimestamp
ts
=
new
MastershipBasedTimestamp
(
termNumber
,
DeviceMastershipBasedTimestamp
ts
=
new
Device
MastershipBasedTimestamp
(
termNumber
,
sequenceNumber
);
assertEquals
(
termNumber
,
ts
.
termNumber
());
...
...
@@ -35,7 +34,7 @@ public class MastershipBasedTimestampTest {
@Test
public
final
void
testCompareTo
()
{
assertTrue
(
TS_1_1
.
compareTo
(
TS_1_1
)
==
0
);
assertTrue
(
TS_1_1
.
compareTo
(
new
MastershipBasedTimestamp
(
1
,
1
))
==
0
);
assertTrue
(
TS_1_1
.
compareTo
(
new
Device
MastershipBasedTimestamp
(
1
,
1
))
==
0
);
assertTrue
(
TS_1_1
.
compareTo
(
TS_1_2
)
<
0
);
assertTrue
(
TS_1_2
.
compareTo
(
TS_1_1
)
>
0
);
...
...
@@ -49,14 +48,14 @@ public class MastershipBasedTimestampTest {
@Test
public
final
void
testEqualsObject
()
{
new
EqualsTester
()
.
addEqualityGroup
(
new
MastershipBasedTimestamp
(
1
,
1
),
new
MastershipBasedTimestamp
(
1
,
1
),
TS_1_1
)
.
addEqualityGroup
(
new
MastershipBasedTimestamp
(
1
,
2
),
new
MastershipBasedTimestamp
(
1
,
2
),
TS_1_2
)
.
addEqualityGroup
(
new
MastershipBasedTimestamp
(
2
,
1
),
new
MastershipBasedTimestamp
(
2
,
1
),
TS_2_1
)
.
addEqualityGroup
(
new
MastershipBasedTimestamp
(
2
,
2
),
new
MastershipBasedTimestamp
(
2
,
2
),
TS_2_2
)
.
addEqualityGroup
(
new
Device
MastershipBasedTimestamp
(
1
,
1
),
new
Device
MastershipBasedTimestamp
(
1
,
1
),
TS_1_1
)
.
addEqualityGroup
(
new
Device
MastershipBasedTimestamp
(
1
,
2
),
new
Device
MastershipBasedTimestamp
(
1
,
2
),
TS_1_2
)
.
addEqualityGroup
(
new
Device
MastershipBasedTimestamp
(
2
,
1
),
new
Device
MastershipBasedTimestamp
(
2
,
1
),
TS_2_1
)
.
addEqualityGroup
(
new
Device
MastershipBasedTimestamp
(
2
,
2
),
new
Device
MastershipBasedTimestamp
(
2
,
2
),
TS_2_2
)
.
testEquals
();
}
...
...
@@ -64,7 +63,7 @@ public class MastershipBasedTimestampTest {
public
final
void
testKryoSerializable
()
{
final
ByteBuffer
buffer
=
ByteBuffer
.
allocate
(
1
*
1024
*
1024
);
final
KryoPool
kryos
=
KryoPool
.
newBuilder
()
.
register
(
MastershipBasedTimestamp
.
class
)
.
register
(
Device
MastershipBasedTimestamp
.
class
)
.
build
();
kryos
.
serialize
(
TS_2_1
,
buffer
);
...
...
@@ -80,7 +79,7 @@ public class MastershipBasedTimestampTest {
public
final
void
testKryoSerializableWithHandcraftedSerializer
()
{
final
ByteBuffer
buffer
=
ByteBuffer
.
allocate
(
1
*
1024
*
1024
);
final
KryoPool
kryos
=
KryoPool
.
newBuilder
()
.
register
(
MastershipBasedTimestamp
.
class
,
new
MastershipBasedTimestampSerializer
())
.
register
(
Device
MastershipBasedTimestamp
.
class
,
new
MastershipBasedTimestampSerializer
())
.
build
();
kryos
.
serialize
(
TS_1_2
,
buffer
);
...
...
core/store/dist/src/test/java/org/onlab/onos/store/common/impl/TimestampedTest.java
View file @
26673ba
...
...
@@ -6,6 +6,7 @@ import java.nio.ByteBuffer;
import
org.junit.Test
;
import
org.onlab.onos.store.Timestamp
;
import
org.onlab.onos.store.Timestamped
;
import
org.onlab.util.KryoPool
;
import
com.google.common.testing.EqualsTester
;
...
...
@@ -15,9 +16,9 @@ import com.google.common.testing.EqualsTester;
*/
public
class
TimestampedTest
{
private
static
final
Timestamp
TS_1_1
=
new
MastershipBasedTimestamp
(
1
,
1
);
private
static
final
Timestamp
TS_1_2
=
new
MastershipBasedTimestamp
(
1
,
2
);
private
static
final
Timestamp
TS_2_1
=
new
MastershipBasedTimestamp
(
2
,
1
);
private
static
final
Timestamp
TS_1_1
=
new
Device
MastershipBasedTimestamp
(
1
,
1
);
private
static
final
Timestamp
TS_1_2
=
new
Device
MastershipBasedTimestamp
(
1
,
2
);
private
static
final
Timestamp
TS_2_1
=
new
Device
MastershipBasedTimestamp
(
2
,
1
);
@Test
public
final
void
testHashCode
()
{
...
...
@@ -79,7 +80,7 @@ public class TimestampedTest {
final
ByteBuffer
buffer
=
ByteBuffer
.
allocate
(
1
*
1024
*
1024
);
final
KryoPool
kryos
=
KryoPool
.
newBuilder
()
.
register
(
Timestamped
.
class
,
MastershipBasedTimestamp
.
class
)
Device
MastershipBasedTimestamp
.
class
)
.
build
();
Timestamped
<
String
>
original
=
new
Timestamped
<>(
"foobar"
,
TS_1_1
);
...
...
core/store/dist/src/test/java/org/onlab/onos/store/device/impl/GossipDeviceStoreTest.java
View file @
26673ba
...
...
@@ -25,7 +25,6 @@ import org.onlab.onos.cluster.ClusterService;
import
org.onlab.onos.cluster.ControllerNode
;
import
org.onlab.onos.cluster.ControllerNode.State
;
import
org.onlab.onos.cluster.DefaultControllerNode
;
import
org.onlab.onos.cluster.MastershipTerm
;
import
org.onlab.onos.cluster.NodeId
;
import
org.onlab.onos.net.Annotations
;
import
org.onlab.onos.net.DefaultAnnotations
;
...
...
@@ -40,6 +39,7 @@ import org.onlab.onos.net.device.DeviceDescription;
import
org.onlab.onos.net.device.DeviceEvent
;
import
org.onlab.onos.net.device.DeviceStore
;
import
org.onlab.onos.net.device.DeviceStoreDelegate
;
import
org.onlab.onos.net.device.DeviceMastershipTerm
;
import
org.onlab.onos.net.device.PortDescription
;
import
org.onlab.onos.net.provider.ProviderId
;
import
org.onlab.onos.store.ClockService
;
...
...
@@ -113,8 +113,8 @@ public class GossipDeviceStoreTest {
deviceClockManager
.
activate
();
clockService
=
deviceClockManager
;
deviceClockManager
.
setMastershipTerm
(
DID1
,
MastershipTerm
.
of
(
MYSELF
,
1
));
deviceClockManager
.
setMastershipTerm
(
DID2
,
MastershipTerm
.
of
(
MYSELF
,
2
));
deviceClockManager
.
setMastershipTerm
(
DID1
,
Device
MastershipTerm
.
of
(
MYSELF
,
1
));
deviceClockManager
.
setMastershipTerm
(
DID2
,
Device
MastershipTerm
.
of
(
MYSELF
,
2
));
ClusterCommunicationService
clusterCommunicator
=
new
TestClusterCommunicationService
();
ClusterService
clusterService
=
new
TestClusterService
();
...
...
core/store/hz/cluster/src/main/java/org/onlab/onos/store/cluster/impl/DistributedMastershipStore.java
View file @
26673ba
package
org
.
onlab
.
onos
.
store
.
cluster
.
impl
;
import
static
org
.
onlab
.
onos
.
cluster
.
MastershipEvent
.
Type
.
MASTER_CHANGED
;
import
static
org
.
onlab
.
onos
.
net
.
device
.
Device
MastershipEvent
.
Type
.
MASTER_CHANGED
;
import
java.util.Map
;
import
java.util.Set
;
...
...
@@ -12,13 +12,13 @@ import org.apache.felix.scr.annotations.Reference;
import
org.apache.felix.scr.annotations.ReferenceCardinality
;
import
org.apache.felix.scr.annotations.Service
;
import
org.onlab.onos.cluster.ClusterService
;
import
org.onlab.onos.cluster.MastershipEvent
;
import
org.onlab.onos.cluster.MastershipStore
;
import
org.onlab.onos.cluster.MastershipStoreDelegate
;
import
org.onlab.onos.cluster.MastershipTerm
;
import
org.onlab.onos.cluster.NodeId
;
import
org.onlab.onos.net.DeviceId
;
import
org.onlab.onos.net.MastershipRole
;
import
org.onlab.onos.net.device.DeviceMastershipEvent
;
import
org.onlab.onos.net.device.DeviceMastershipStore
;
import
org.onlab.onos.net.device.DeviceMastershipStoreDelegate
;
import
org.onlab.onos.net.device.DeviceMastershipTerm
;
import
org.onlab.onos.store.common.AbstractHazelcastStore
;
import
com.google.common.collect.ImmutableSet
;
...
...
@@ -33,8 +33,8 @@ import com.hazelcast.core.MultiMap;
@Component
(
immediate
=
true
)
@Service
public
class
DistributedMastershipStore
extends
AbstractHazelcastStore
<
MastershipEvent
,
MastershipStoreDelegate
>
implements
MastershipStore
{
extends
AbstractHazelcastStore
<
DeviceMastershipEvent
,
Device
MastershipStoreDelegate
>
implements
Device
MastershipStore
{
//arbitrary lock name
private
static
final
String
LOCK
=
"lock"
;
...
...
@@ -100,7 +100,7 @@ implements MastershipStore {
}
@Override
public
MastershipEvent
setMaster
(
NodeId
nodeId
,
DeviceId
deviceId
)
{
public
Device
MastershipEvent
setMaster
(
NodeId
nodeId
,
DeviceId
deviceId
)
{
byte
[]
did
=
serialize
(
deviceId
);
byte
[]
nid
=
serialize
(
nodeId
);
...
...
@@ -123,12 +123,12 @@ implements MastershipStore {
masters
.
put
(
did
,
nid
);
evict
(
nid
,
did
);
updateTerm
(
did
);
return
new
MastershipEvent
(
MASTER_CHANGED
,
deviceId
,
nodeId
);
return
new
Device
MastershipEvent
(
MASTER_CHANGED
,
deviceId
,
nodeId
);
case
NONE:
masters
.
put
(
did
,
nid
);
evict
(
nid
,
did
);
updateTerm
(
did
);
return
new
MastershipEvent
(
MASTER_CHANGED
,
deviceId
,
nodeId
);
return
new
Device
MastershipEvent
(
MASTER_CHANGED
,
deviceId
,
nodeId
);
default
:
log
.
warn
(
"unknown Mastership Role {}"
,
role
);
return
null
;
...
...
@@ -191,21 +191,21 @@ implements MastershipStore {
}
@Override
public
MastershipTerm
getTermFor
(
DeviceId
deviceId
)
{
public
Device
MastershipTerm
getTermFor
(
DeviceId
deviceId
)
{
byte
[]
did
=
serialize
(
deviceId
);
if
((
masters
.
get
(
did
)
==
null
)
||
(
terms
.
get
(
did
)
==
null
))
{
return
null
;
}
return
MastershipTerm
.
of
(
return
Device
MastershipTerm
.
of
(
(
NodeId
)
deserialize
(
masters
.
get
(
did
)),
terms
.
get
(
did
));
}
@Override
public
MastershipEvent
setStandby
(
NodeId
nodeId
,
DeviceId
deviceId
)
{
public
Device
MastershipEvent
setStandby
(
NodeId
nodeId
,
DeviceId
deviceId
)
{
byte
[]
did
=
serialize
(
deviceId
);
byte
[]
nid
=
serialize
(
nodeId
);
MastershipEvent
event
=
null
;
Device
MastershipEvent
event
=
null
;
ILock
lock
=
theInstance
.
getLock
(
LOCK
);
lock
.
lock
();
...
...
@@ -231,10 +231,10 @@ implements MastershipStore {
}
@Override
public
MastershipEvent
relinquishRole
(
NodeId
nodeId
,
DeviceId
deviceId
)
{
public
Device
MastershipEvent
relinquishRole
(
NodeId
nodeId
,
DeviceId
deviceId
)
{
byte
[]
did
=
serialize
(
deviceId
);
byte
[]
nid
=
serialize
(
nodeId
);
MastershipEvent
event
=
null
;
Device
MastershipEvent
event
=
null
;
ILock
lock
=
theInstance
.
getLock
(
LOCK
);
lock
.
lock
();
...
...
@@ -260,7 +260,7 @@ implements MastershipStore {
}
//helper to fetch a new master candidate for a given device.
private
MastershipEvent
reelect
(
NodeId
current
,
DeviceId
deviceId
)
{
private
Device
MastershipEvent
reelect
(
NodeId
current
,
DeviceId
deviceId
)
{
byte
[]
did
=
serialize
(
deviceId
);
byte
[]
nid
=
serialize
(
current
);
...
...
@@ -281,7 +281,7 @@ implements MastershipStore {
evict
(
backup
,
did
);
Integer
term
=
terms
.
get
(
did
);
terms
.
put
(
did
,
++
term
);
return
new
MastershipEvent
(
return
new
Device
MastershipEvent
(
MASTER_CHANGED
,
deviceId
,
(
NodeId
)
deserialize
(
backup
));
}
}
...
...
@@ -320,7 +320,7 @@ implements MastershipStore {
@Override
protected
void
onAdd
(
DeviceId
deviceId
,
NodeId
nodeId
)
{
notifyDelegate
(
new
MastershipEvent
(
MASTER_CHANGED
,
deviceId
,
nodeId
));
notifyDelegate
(
new
Device
MastershipEvent
(
MASTER_CHANGED
,
deviceId
,
nodeId
));
}
@Override
...
...
core/store/hz/cluster/src/test/java/org/onlab/onos/store/cluster/impl/DistributedMastershipStoreTest.java
View file @
26673ba
...
...
@@ -21,12 +21,12 @@ import org.onlab.onos.cluster.ClusterService;
import
org.onlab.onos.cluster.ControllerNode
;
import
org.onlab.onos.cluster.ControllerNode.State
;
import
org.onlab.onos.cluster.DefaultControllerNode
;
import
org.onlab.onos.cluster.MastershipEvent
;
import
org.onlab.onos.cluster.MastershipEvent.Type
;
import
org.onlab.onos.cluster.MastershipStoreDelegate
;
import
org.onlab.onos.cluster.MastershipTerm
;
import
org.onlab.onos.cluster.NodeId
;
import
org.onlab.onos.net.DeviceId
;
import
org.onlab.onos.net.device.DeviceMastershipEvent
;
import
org.onlab.onos.net.device.DeviceMastershipStoreDelegate
;
import
org.onlab.onos.net.device.DeviceMastershipTerm
;
import
org.onlab.onos.net.device.DeviceMastershipEvent.Type
;
import
org.onlab.onos.store.common.StoreManager
;
import
org.onlab.onos.store.common.StoreService
;
import
org.onlab.onos.store.common.TestStoreManager
;
...
...
@@ -133,7 +133,7 @@ public class DistributedMastershipStoreTest {
assertEquals
(
"wrong role for NONE:"
,
MASTER
,
dms
.
requestRole
(
DID1
));
assertTrue
(
"wrong state for store:"
,
!
dms
.
terms
.
isEmpty
());
assertEquals
(
"wrong term"
,
MastershipTerm
.
of
(
N1
,
0
),
dms
.
getTermFor
(
DID1
));
Device
MastershipTerm
.
of
(
N1
,
0
),
dms
.
getTermFor
(
DID1
));
//CN2 now local. DID2 has N1 as MASTER so N2 is STANDBY
testStore
.
setCurrent
(
CN2
);
...
...
@@ -143,7 +143,7 @@ public class DistributedMastershipStoreTest {
//change term and requestRole() again; should persist
testStore
.
increment
(
DID2
);
assertEquals
(
"wrong role for STANDBY:"
,
STANDBY
,
dms
.
requestRole
(
DID2
));
assertEquals
(
"wrong term"
,
MastershipTerm
.
of
(
N1
,
1
),
dms
.
getTermFor
(
DID2
));
assertEquals
(
"wrong term"
,
Device
MastershipTerm
.
of
(
N1
,
1
),
dms
.
getTermFor
(
DID2
));
}
@Test
...
...
@@ -155,15 +155,15 @@ public class DistributedMastershipStoreTest {
//switch over to N2
assertEquals
(
"wrong event:"
,
Type
.
MASTER_CHANGED
,
dms
.
setMaster
(
N2
,
DID1
).
type
());
assertEquals
(
"wrong term"
,
MastershipTerm
.
of
(
N2
,
1
),
dms
.
getTermFor
(
DID1
));
assertEquals
(
"wrong term"
,
Device
MastershipTerm
.
of
(
N2
,
1
),
dms
.
getTermFor
(
DID1
));
//orphan switch - should be rare case
assertEquals
(
"wrong event:"
,
Type
.
MASTER_CHANGED
,
dms
.
setMaster
(
N2
,
DID2
).
type
());
assertEquals
(
"wrong term"
,
MastershipTerm
.
of
(
N2
,
0
),
dms
.
getTermFor
(
DID2
));
assertEquals
(
"wrong term"
,
Device
MastershipTerm
.
of
(
N2
,
0
),
dms
.
getTermFor
(
DID2
));
//disconnect and reconnect - sign of failing re-election or single-instance channel
testStore
.
reset
(
true
,
false
,
false
);
dms
.
setMaster
(
N2
,
DID2
);
assertEquals
(
"wrong term"
,
MastershipTerm
.
of
(
N2
,
1
),
dms
.
getTermFor
(
DID2
));
assertEquals
(
"wrong term"
,
Device
MastershipTerm
.
of
(
N2
,
1
),
dms
.
getTermFor
(
DID2
));
}
@Test
...
...
@@ -211,9 +211,9 @@ public class DistributedMastershipStoreTest {
//shamelessly copy other distributed store tests
final
CountDownLatch
addLatch
=
new
CountDownLatch
(
1
);
MastershipStoreDelegate
checkAdd
=
new
MastershipStoreDelegate
()
{
DeviceMastershipStoreDelegate
checkAdd
=
new
Device
MastershipStoreDelegate
()
{
@Override
public
void
notify
(
MastershipEvent
event
)
{
public
void
notify
(
Device
MastershipEvent
event
)
{
assertEquals
(
"wrong event:"
,
Type
.
MASTER_CHANGED
,
event
.
type
());
assertEquals
(
"wrong subject"
,
DID1
,
event
.
subject
());
assertEquals
(
"wrong subject"
,
N1
,
event
.
master
());
...
...
core/store/hz/net/src/main/java/org/onlab/onos/store/device/impl/NoOpClockProviderService.java
View file @
26673ba
...
...
@@ -2,8 +2,8 @@ package org.onlab.onos.store.device.impl;
import
org.apache.felix.scr.annotations.Component
;
import
org.apache.felix.scr.annotations.Service
;
import
org.onlab.onos.cluster.MastershipTerm
;
import
org.onlab.onos.net.DeviceId
;
import
org.onlab.onos.net.device.DeviceMastershipTerm
;
import
org.onlab.onos.store.ClockProviderService
;
// FIXME: Code clone in onos-core-trivial, onos-core-hz-net
...
...
@@ -15,6 +15,6 @@ import org.onlab.onos.store.ClockProviderService;
public
class
NoOpClockProviderService
implements
ClockProviderService
{
@Override
public
void
setMastershipTerm
(
DeviceId
deviceId
,
MastershipTerm
term
)
{
public
void
setMastershipTerm
(
DeviceId
deviceId
,
Device
MastershipTerm
term
)
{
}
}
...
...
core/store/serializers/src/main/java/org/onlab/onos/store/serializers/KryoPoolUtil.java
View file @
26673ba
...
...
@@ -7,7 +7,6 @@ import java.util.HashMap;
import
org.onlab.onos.cluster.ControllerNode
;
import
org.onlab.onos.cluster.DefaultControllerNode
;
import
org.onlab.onos.cluster.MastershipTerm
;
import
org.onlab.onos.cluster.NodeId
;
import
org.onlab.onos.net.ConnectPoint
;
import
org.onlab.onos.net.DefaultAnnotations
;
...
...
@@ -24,6 +23,7 @@ import org.onlab.onos.net.Port;
import
org.onlab.onos.net.PortNumber
;
import
org.onlab.onos.net.device.DefaultDeviceDescription
;
import
org.onlab.onos.net.device.DefaultPortDescription
;
import
org.onlab.onos.net.device.DeviceMastershipTerm
;
import
org.onlab.onos.net.provider.ProviderId
;
import
org.onlab.packet.IpAddress
;
import
org.onlab.packet.IpPrefix
;
...
...
@@ -74,7 +74,7 @@ public final class KryoPoolUtil {
.
register
(
LinkKey
.
class
,
new
LinkKeySerializer
())
.
register
(
ConnectPoint
.
class
,
new
ConnectPointSerializer
())
.
register
(
DefaultLink
.
class
,
new
DefaultLinkSerializer
())
.
register
(
MastershipTerm
.
class
,
new
MastershipTermSerializer
())
.
register
(
Device
MastershipTerm
.
class
,
new
MastershipTermSerializer
())
.
register
(
MastershipRole
.
class
,
new
MastershipRoleSerializer
())
.
build
();
...
...
core/store/serializers/src/main/java/org/onlab/onos/store/serializers/MastershipTermSerializer.java
View file @
26673ba
package
org
.
onlab
.
onos
.
store
.
serializers
;
import
org.onlab.onos.cluster.MastershipTerm
;
import
org.onlab.onos.cluster.NodeId
;
import
org.onlab.onos.net.device.DeviceMastershipTerm
;
import
com.esotericsoftware.kryo.Kryo
;
import
com.esotericsoftware.kryo.Serializer
;
import
com.esotericsoftware.kryo.io.Input
;
import
com.esotericsoftware.kryo.io.Output
;
/**
* Kryo Serializer for {@link org.onlab.onos.
cluster.
MastershipTerm}.
* Kryo Serializer for {@link org.onlab.onos.
net.device.Device
MastershipTerm}.
*/
public
class
MastershipTermSerializer
extends
Serializer
<
MastershipTerm
>
{
public
class
MastershipTermSerializer
extends
Serializer
<
Device
MastershipTerm
>
{
/**
* Creates {@link MastershipTerm} serializer instance.
* Creates {@link
Device
MastershipTerm} serializer instance.
*/
public
MastershipTermSerializer
()
{
// non-null, immutable
...
...
@@ -21,14 +22,14 @@ public class MastershipTermSerializer extends Serializer<MastershipTerm> {
}
@Override
public
MastershipTerm
read
(
Kryo
kryo
,
Input
input
,
Class
<
MastershipTerm
>
type
)
{
public
DeviceMastershipTerm
read
(
Kryo
kryo
,
Input
input
,
Class
<
Device
MastershipTerm
>
type
)
{
final
NodeId
node
=
new
NodeId
(
input
.
readString
());
final
int
term
=
input
.
readInt
();
return
MastershipTerm
.
of
(
node
,
term
);
return
Device
MastershipTerm
.
of
(
node
,
term
);
}
@Override
public
void
write
(
Kryo
kryo
,
Output
output
,
MastershipTerm
object
)
{
public
void
write
(
Kryo
kryo
,
Output
output
,
Device
MastershipTerm
object
)
{
output
.
writeString
(
object
.
master
().
toString
());
output
.
writeInt
(
object
.
termNumber
());
}
...
...
core/store/serializers/src/test/java/org/onlab/onos/store/serializers/KryoSerializerTest.java
View file @
26673ba
...
...
@@ -10,7 +10,6 @@ import org.junit.After;
import
org.junit.Before
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
import
org.onlab.onos.cluster.MastershipTerm
;
import
org.onlab.onos.cluster.NodeId
;
import
org.onlab.onos.net.Annotations
;
import
org.onlab.onos.net.ConnectPoint
;
...
...
@@ -25,6 +24,7 @@ import org.onlab.onos.net.LinkKey;
import
org.onlab.onos.net.MastershipRole
;
import
org.onlab.onos.net.PortNumber
;
import
org.onlab.onos.net.SparseAnnotations
;
import
org.onlab.onos.net.device.DeviceMastershipTerm
;
import
org.onlab.onos.net.provider.ProviderId
;
import
org.onlab.packet.IpAddress
;
import
org.onlab.packet.IpPrefix
;
...
...
@@ -114,7 +114,7 @@ public class KryoSerializerTest {
testSerialized
(
PID
);
testSerialized
(
PIDA
);
testSerialized
(
new
NodeId
(
"bar"
));
testSerialized
(
MastershipTerm
.
of
(
new
NodeId
(
"foo"
),
2
));
testSerialized
(
Device
MastershipTerm
.
of
(
new
NodeId
(
"foo"
),
2
));
for
(
MastershipRole
role
:
MastershipRole
.
values
())
{
testSerialized
(
role
);
}
...
...
core/store/trivial/src/main/java/org/onlab/onos/store/trivial/impl/NoOpClockProviderService.java
View file @
26673ba
...
...
@@ -2,8 +2,8 @@ package org.onlab.onos.store.trivial.impl;
import
org.apache.felix.scr.annotations.Component
;
import
org.apache.felix.scr.annotations.Service
;
import
org.onlab.onos.cluster.MastershipTerm
;
import
org.onlab.onos.net.DeviceId
;
import
org.onlab.onos.net.device.DeviceMastershipTerm
;
import
org.onlab.onos.store.ClockProviderService
;
//FIXME: Code clone in onos-core-trivial, onos-core-hz-net
...
...
@@ -15,6 +15,6 @@ import org.onlab.onos.store.ClockProviderService;
public
class
NoOpClockProviderService
implements
ClockProviderService
{
@Override
public
void
setMastershipTerm
(
DeviceId
deviceId
,
MastershipTerm
term
)
{
public
void
setMastershipTerm
(
DeviceId
deviceId
,
Device
MastershipTerm
term
)
{
}
}
...
...
core/store/trivial/src/main/java/org/onlab/onos/store/trivial/impl/SimpleMastershipStore.java
View file @
26673ba
...
...
@@ -15,18 +15,18 @@ import org.apache.felix.scr.annotations.Deactivate;
import
org.apache.felix.scr.annotations.Service
;
import
org.onlab.onos.cluster.ControllerNode
;
import
org.onlab.onos.cluster.DefaultControllerNode
;
import
org.onlab.onos.cluster.MastershipEvent
;
import
org.onlab.onos.cluster.MastershipStore
;
import
org.onlab.onos.cluster.MastershipStoreDelegate
;
import
org.onlab.onos.cluster.MastershipTerm
;
import
org.onlab.onos.cluster.NodeId
;
import
org.onlab.onos.net.DeviceId
;
import
org.onlab.onos.net.MastershipRole
;
import
org.onlab.onos.net.device.DeviceMastershipEvent
;
import
org.onlab.onos.net.device.DeviceMastershipStore
;
import
org.onlab.onos.net.device.DeviceMastershipStoreDelegate
;
import
org.onlab.onos.net.device.DeviceMastershipTerm
;
import
org.onlab.onos.store.AbstractStore
;
import
org.onlab.packet.IpPrefix
;
import
org.slf4j.Logger
;
import
static
org
.
onlab
.
onos
.
cluster
.
MastershipEvent
.
Type
.*;
import
static
org
.
onlab
.
onos
.
net
.
device
.
Device
MastershipEvent
.
Type
.*;
/**
* Manages inventory of controller mastership over devices using
...
...
@@ -35,8 +35,8 @@ import static org.onlab.onos.cluster.MastershipEvent.Type.*;
@Component
(
immediate
=
true
)
@Service
public
class
SimpleMastershipStore
extends
AbstractStore
<
MastershipEvent
,
MastershipStoreDelegate
>
implements
MastershipStore
{
extends
AbstractStore
<
DeviceMastershipEvent
,
Device
MastershipStoreDelegate
>
implements
Device
MastershipStore
{
private
final
Logger
log
=
getLogger
(
getClass
());
...
...
@@ -63,7 +63,7 @@ public class SimpleMastershipStore
}
@Override
public
MastershipEvent
setMaster
(
NodeId
nodeId
,
DeviceId
deviceId
)
{
public
Device
MastershipEvent
setMaster
(
NodeId
nodeId
,
DeviceId
deviceId
)
{
MastershipRole
role
=
getRole
(
nodeId
,
deviceId
);
synchronized
(
this
)
{
...
...
@@ -86,7 +86,7 @@ public class SimpleMastershipStore
}
}
return
new
MastershipEvent
(
MASTER_CHANGED
,
deviceId
,
nodeId
);
return
new
Device
MastershipEvent
(
MASTER_CHANGED
,
deviceId
,
nodeId
);
}
@Override
...
...
@@ -164,17 +164,17 @@ public class SimpleMastershipStore
}
@Override
public
MastershipTerm
getTermFor
(
DeviceId
deviceId
)
{
public
Device
MastershipTerm
getTermFor
(
DeviceId
deviceId
)
{
if
((
masterMap
.
get
(
deviceId
)
==
null
)
||
(
termMap
.
get
(
deviceId
)
==
null
))
{
return
null
;
}
return
MastershipTerm
.
of
(
return
Device
MastershipTerm
.
of
(
masterMap
.
get
(
deviceId
),
termMap
.
get
(
deviceId
).
get
());
}
@Override
public
MastershipEvent
setStandby
(
NodeId
nodeId
,
DeviceId
deviceId
)
{
public
Device
MastershipEvent
setStandby
(
NodeId
nodeId
,
DeviceId
deviceId
)
{
MastershipRole
role
=
getRole
(
nodeId
,
deviceId
);
synchronized
(
this
)
{
switch
(
role
)
{
...
...
@@ -185,7 +185,7 @@ public class SimpleMastershipStore
}
else
{
masterMap
.
put
(
deviceId
,
backup
);
termMap
.
get
(
deviceId
).
incrementAndGet
();
return
new
MastershipEvent
(
MASTER_CHANGED
,
deviceId
,
backup
);
return
new
Device
MastershipEvent
(
MASTER_CHANGED
,
deviceId
,
backup
);
}
case
STANDBY:
case
NONE:
...
...
@@ -215,7 +215,7 @@ public class SimpleMastershipStore
}
@Override
public
MastershipEvent
relinquishRole
(
NodeId
nodeId
,
DeviceId
deviceId
)
{
public
Device
MastershipEvent
relinquishRole
(
NodeId
nodeId
,
DeviceId
deviceId
)
{
return
setStandby
(
nodeId
,
deviceId
);
}
...
...
core/store/trivial/src/test/java/org/onlab/onos/store/trivial/impl/SimpleMastershipStoreTest.java
View file @
26673ba
...
...
@@ -6,9 +6,9 @@ import java.util.concurrent.atomic.AtomicInteger;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.onlab.onos.cluster.MastershipTerm
;
import
org.onlab.onos.cluster.NodeId
;
import
org.onlab.onos.net.DeviceId
;
import
org.onlab.onos.net.device.DeviceMastershipTerm
;
import
com.google.common.collect.Sets
;
...
...
@@ -16,7 +16,7 @@ import static org.junit.Assert.assertEquals;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
onlab
.
onos
.
net
.
MastershipRole
.*;
import
static
org
.
onlab
.
onos
.
cluster
.
MastershipEvent
.
Type
.*;
import
static
org
.
onlab
.
onos
.
net
.
device
.
Device
MastershipEvent
.
Type
.*;
/**
* Test for the simple MastershipStore implementation.
...
...
@@ -98,12 +98,12 @@ public class SimpleMastershipStoreTest {
@Test
public
void
getTermFor
()
{
put
(
DID1
,
N1
,
true
,
true
);
assertEquals
(
"wrong term"
,
MastershipTerm
.
of
(
N1
,
0
),
sms
.
getTermFor
(
DID1
));
assertEquals
(
"wrong term"
,
Device
MastershipTerm
.
of
(
N1
,
0
),
sms
.
getTermFor
(
DID1
));
//switch to N2 and back - 2 term switches
sms
.
setMaster
(
N2
,
DID1
);
sms
.
setMaster
(
N1
,
DID1
);
assertEquals
(
"wrong term"
,
MastershipTerm
.
of
(
N1
,
2
),
sms
.
getTermFor
(
DID1
));
assertEquals
(
"wrong term"
,
Device
MastershipTerm
.
of
(
N1
,
2
),
sms
.
getTermFor
(
DID1
));
}
@Test
...
...
Please
register
or
login
to post a comment