Toggle navigation
Toggle navigation
This project
Loading...
Sign in
홍길동
/
onos
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Thomas Vachuska
2014-10-21 12:47:34 -0700
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
07ac62ab2e627020360754ca8e83fe74ac9d5bb5
07ac62ab
2 parents
10d4abcf
fc981cff
Merge remote-tracking branch 'origin/master'
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
89 additions
and
50 deletions
apps/fwd/src/main/java/org/onlab/onos/fwd/ReactiveForwarding.java
cli/src/main/java/org/onlab/onos/cli/RolesCommand.java
core/api/src/main/java/org/onlab/onos/cluster/RoleInfo.java
core/api/src/main/java/org/onlab/onos/mastership/MastershipEvent.java
core/api/src/main/java/org/onlab/onos/net/flow/DefaultFlowEntry.java
core/api/src/main/java/org/onlab/onos/net/flow/DefaultFlowRule.java
core/api/src/main/java/org/onlab/onos/net/flow/FlowRule.java
core/net/src/main/java/org/onlab/onos/net/flow/impl/FlowRuleManager.java
core/net/src/main/java/org/onlab/onos/net/intent/impl/LinkCollectionIntentInstaller.java
core/net/src/main/java/org/onlab/onos/net/intent/impl/PathIntentInstaller.java
core/net/src/test/java/org/onlab/onos/net/flow/impl/FlowRuleManagerTest.java
core/store/dist/src/test/java/org/onlab/onos/store/flow/impl/ReplicaInfoManagerTest.java
core/store/hz/cluster/src/main/java/org/onlab/onos/store/mastership/impl/DistributedMastershipStore.java
core/store/hz/cluster/src/main/java/org/onlab/onos/store/mastership/impl/RoleValue.java
core/store/trivial/src/main/java/org/onlab/onos/store/trivial/impl/SimpleMastershipStore.java
providers/openflow/flow/src/main/java/org/onlab/onos/provider/of/flow/impl/FlowEntryBuilder.java
apps/fwd/src/main/java/org/onlab/onos/fwd/ReactiveForwarding.java
View file @
07ac62a
package
org
.
onlab
.
onos
.
fwd
;
import
static
org
.
slf4j
.
LoggerFactory
.
getLogger
;
import
java.util.Dictionary
;
import
java.util.Set
;
import
org.apache.felix.scr.annotations.Activate
;
import
org.apache.felix.scr.annotations.Component
;
import
org.apache.felix.scr.annotations.Deactivate
;
...
...
@@ -30,11 +35,6 @@ import org.onlab.packet.Ethernet;
import
org.osgi.service.component.ComponentContext
;
import
org.slf4j.Logger
;
import
java.util.Dictionary
;
import
java.util.Set
;
import
static
org
.
slf4j
.
LoggerFactory
.
getLogger
;
/**
* Sample reactive forwarding application.
*/
...
...
@@ -206,7 +206,7 @@ public class ReactiveForwarding {
treat
.
setOutput
(
portNumber
);
FlowRule
f
=
new
DefaultFlowRule
(
context
.
inPacket
().
receivedFrom
().
deviceId
(),
builder
.
build
(),
treat
.
build
(),
PRIORITY
,
appId
,
TIMEOUT
);
builder
.
build
(),
treat
.
build
(),
PRIORITY
,
appId
,
TIMEOUT
,
false
);
flowRuleService
.
applyFlowRules
(
f
);
}
...
...
cli/src/main/java/org/onlab/onos/cli/RolesCommand.java
View file @
07ac62a
...
...
@@ -21,7 +21,7 @@ import org.onlab.onos.net.device.DeviceService;
description
=
"Lists mastership roles of nodes for each device."
)
public
class
RolesCommand
extends
AbstractShellCommand
{
private
static
final
String
FMT_HDR
=
"%s: master=%s, standbys=
%s
"
;
private
static
final
String
FMT_HDR
=
"%s: master=%s, standbys=
[ %s]
"
;
@Override
protected
void
execute
()
{
...
...
core/api/src/main/java/org/onlab/onos/cluster/RoleInfo.java
View file @
07ac62a
...
...
@@ -3,10 +3,11 @@ package org.onlab.onos.cluster;
import
java.util.List
;
import
java.util.Objects
;
import
com.google.common.base.MoreObjects
;
import
com.google.common.collect.ImmutableList
;
/**
* A
container for detailed
role information for a device,
* A
n immutable container for
role information for a device,
* within the current cluster. Role attributes include current
* master and a preference-ordered list of backup nodes.
*/
...
...
@@ -52,12 +53,9 @@ public class RoleInfo {
@Override
public
String
toString
()
{
final
StringBuilder
builder
=
new
StringBuilder
();
builder
.
append
(
"master:"
).
append
(
master
).
append
(
","
);
builder
.
append
(
"backups:"
);
for
(
NodeId
n
:
backups
)
{
builder
.
append
(
" "
).
append
(
n
);
}
return
builder
.
toString
();
return
MoreObjects
.
toStringHelper
(
this
.
getClass
())
.
add
(
"master"
,
master
)
.
add
(
"backups"
,
backups
)
.
toString
();
}
}
...
...
core/api/src/main/java/org/onlab/onos/mastership/MastershipEvent.java
View file @
07ac62a
package
org
.
onlab
.
onos
.
mastership
;
import
org.onlab.onos.cluster.NodeId
;
import
org.onlab.onos.cluster.RoleInfo
;
import
org.onlab.onos.event.AbstractEvent
;
import
org.onlab.onos.net.DeviceId
;
...
...
@@ -9,9 +10,8 @@ import org.onlab.onos.net.DeviceId;
*/
public
class
MastershipEvent
extends
AbstractEvent
<
MastershipEvent
.
Type
,
DeviceId
>
{
//do we worry about explicitly setting slaves/equals? probably not,
//to keep it simple
NodeId
node
;
//Contains master and standby information.
RoleInfo
roleInfo
;
/**
* Type of mastership events.
...
...
@@ -29,16 +29,16 @@ public class MastershipEvent extends AbstractEvent<MastershipEvent.Type, DeviceI
}
/**
* Creates an event of a given type and for the specified device,
master,
* and the current time.
* Creates an event of a given type and for the specified device,
*
role information,
and the current time.
*
* @param type device event type
* @param device event device subject
* @param
node master ID
subject
* @param
info mastership role information
subject
*/
public
MastershipEvent
(
Type
type
,
DeviceId
device
,
NodeId
node
)
{
public
MastershipEvent
(
Type
type
,
DeviceId
device
,
RoleInfo
info
)
{
super
(
type
,
device
);
this
.
node
=
node
;
this
.
roleInfo
=
info
;
}
/**
...
...
@@ -50,9 +50,9 @@ 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
MastershipEvent
(
Type
type
,
DeviceId
device
,
RoleInfo
info
,
long
time
)
{
super
(
type
,
device
,
time
);
this
.
node
=
master
;
this
.
roleInfo
=
info
;
}
/**
...
...
@@ -63,7 +63,17 @@ public class MastershipEvent extends AbstractEvent<MastershipEvent.Type, DeviceI
*
* @return node ID as a subject
*/
//XXX to-be removed - or keep for convenience?
public
NodeId
node
()
{
return
node
;
return
roleInfo
.
master
();
}
/**
* Returns the current role state for the subject.
*
* @return RoleInfo associated with Device ID subject
*/
public
RoleInfo
roleInfo
()
{
return
roleInfo
;
}
}
...
...
core/api/src/main/java/org/onlab/onos/net/flow/DefaultFlowEntry.java
View file @
07ac62a
...
...
@@ -27,7 +27,7 @@ public class DefaultFlowEntry extends DefaultFlowRule
TrafficTreatment
treatment
,
int
priority
,
FlowEntryState
state
,
long
life
,
long
packets
,
long
bytes
,
long
flowId
,
int
timeout
)
{
super
(
deviceId
,
selector
,
treatment
,
priority
,
flowId
,
timeout
);
super
(
deviceId
,
selector
,
treatment
,
priority
,
flowId
,
timeout
,
false
);
this
.
state
=
state
;
this
.
life
=
life
;
this
.
packets
=
packets
;
...
...
core/api/src/main/java/org/onlab/onos/net/flow/DefaultFlowRule.java
View file @
07ac62a
...
...
@@ -24,16 +24,18 @@ public class DefaultFlowRule implements FlowRule {
private
final
short
appId
;
private
final
int
timeout
;
private
final
boolean
permanent
;
public
DefaultFlowRule
(
DeviceId
deviceId
,
TrafficSelector
selector
,
TrafficTreatment
treatment
,
int
priority
,
long
flowId
,
int
timeout
)
{
int
timeout
,
boolean
permanent
)
{
this
.
deviceId
=
deviceId
;
this
.
priority
=
priority
;
this
.
selector
=
selector
;
this
.
treatment
=
treatment
;
this
.
timeout
=
timeout
;
this
.
permanent
=
permanent
;
this
.
created
=
System
.
currentTimeMillis
();
this
.
appId
=
(
short
)
(
flowId
>>>
48
);
...
...
@@ -42,7 +44,7 @@ public class DefaultFlowRule implements FlowRule {
public
DefaultFlowRule
(
DeviceId
deviceId
,
TrafficSelector
selector
,
TrafficTreatment
treatement
,
int
priority
,
ApplicationId
appId
,
int
timeout
)
{
int
timeout
,
boolean
permanent
)
{
if
(
priority
<
FlowRule
.
MIN_PRIORITY
)
{
throw
new
IllegalArgumentException
(
"Priority cannot be less than "
+
MIN_PRIORITY
);
...
...
@@ -54,6 +56,7 @@ public class DefaultFlowRule implements FlowRule {
this
.
treatment
=
treatement
;
this
.
appId
=
appId
.
id
();
this
.
timeout
=
timeout
;
this
.
permanent
=
permanent
;
this
.
created
=
System
.
currentTimeMillis
();
this
.
id
=
FlowId
.
valueOf
((((
long
)
this
.
appId
)
<<
48
)
|
(
this
.
hash
()
&
0x0000ffffffff
L
));
...
...
@@ -67,6 +70,7 @@ public class DefaultFlowRule implements FlowRule {
this
.
appId
=
rule
.
appId
();
this
.
id
=
rule
.
id
();
this
.
timeout
=
rule
.
timeout
();
this
.
permanent
=
rule
.
isPermanent
();
this
.
created
=
System
.
currentTimeMillis
();
}
...
...
@@ -157,4 +161,9 @@ public class DefaultFlowRule implements FlowRule {
return
timeout
;
}
@Override
public
boolean
isPermanent
()
{
return
permanent
;
}
}
...
...
core/api/src/main/java/org/onlab/onos/net/flow/FlowRule.java
View file @
07ac62a
...
...
@@ -59,8 +59,16 @@ public interface FlowRule extends BatchOperationTarget {
/**
* Returns the timeout for this flow requested by an application.
*
* @return integer value of the timeout
*/
int
timeout
();
/**
* Returns whether the flow is permanent i.e. does not time out.
*
* @return true if the flow is permanent, otherwise false
*/
boolean
isPermanent
();
}
...
...
core/net/src/main/java/org/onlab/onos/net/flow/impl/FlowRuleManager.java
View file @
07ac62a
...
...
@@ -327,6 +327,10 @@ public class FlowRuleManager
if
(
storedRule
==
null
)
{
return
false
;
}
if
(
storedRule
.
isPermanent
())
{
return
true
;
}
final
long
timeout
=
storedRule
.
timeout
()
*
1000
;
final
long
currentTime
=
System
.
currentTimeMillis
();
if
(
storedRule
.
packets
()
!=
swRule
.
packets
())
{
...
...
core/net/src/main/java/org/onlab/onos/net/intent/impl/LinkCollectionIntentInstaller.java
View file @
07ac62a
...
...
@@ -117,7 +117,7 @@ public class LinkCollectionIntentInstaller implements IntentInstaller<LinkCollec
TrafficTreatment
treatment
=
builder
().
setOutput
(
outPort
).
build
();
FlowRule
rule
=
new
DefaultFlowRule
(
deviceId
,
selector
,
treatment
,
123
,
appId
,
600
);
selector
,
treatment
,
123
,
appId
,
0
,
true
);
return
new
FlowRuleBatchEntry
(
operation
,
rule
);
}
...
...
core/net/src/main/java/org/onlab/onos/net/intent/impl/PathIntentInstaller.java
View file @
07ac62a
...
...
@@ -73,7 +73,7 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> {
FlowRule
rule
=
new
DefaultFlowRule
(
link
.
src
().
deviceId
(),
builder
.
build
(),
treatment
,
123
,
appId
,
15
);
123
,
appId
,
0
,
true
);
rules
.
add
(
new
FlowRuleBatchEntry
(
FlowRuleOperation
.
ADD
,
rule
));
prev
=
link
.
dst
();
}
...
...
@@ -95,7 +95,7 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> {
.
setOutput
(
link
.
src
().
port
()).
build
();
FlowRule
rule
=
new
DefaultFlowRule
(
link
.
src
().
deviceId
(),
builder
.
build
(),
treatment
,
123
,
appId
,
600
);
123
,
appId
,
0
,
true
);
rules
.
add
(
new
FlowRuleBatchEntry
(
FlowRuleOperation
.
REMOVE
,
rule
));
prev
=
link
.
dst
();
}
...
...
core/net/src/test/java/org/onlab/onos/net/flow/impl/FlowRuleManagerTest.java
View file @
07ac62a
package
org
.
onlab
.
onos
.
net
.
flow
.
impl
;
import
static
java
.
util
.
Collections
.
EMPTY_LIST
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assert
.
fail
;
import
static
org
.
onlab
.
onos
.
net
.
flow
.
FlowRuleEvent
.
Type
.
RULE_ADDED
;
import
static
org
.
onlab
.
onos
.
net
.
flow
.
FlowRuleEvent
.
Type
.
RULE_REMOVED
;
import
static
org
.
onlab
.
onos
.
net
.
flow
.
FlowRuleEvent
.
Type
.
RULE_UPDATED
;
...
...
@@ -115,7 +119,7 @@ public class FlowRuleManagerTest {
private
FlowRule
flowRule
(
int
tsval
,
int
trval
)
{
TestSelector
ts
=
new
TestSelector
(
tsval
);
TestTreatment
tr
=
new
TestTreatment
(
trval
);
return
new
DefaultFlowRule
(
DID
,
ts
,
tr
,
10
,
appId
,
TIMEOUT
);
return
new
DefaultFlowRule
(
DID
,
ts
,
tr
,
10
,
appId
,
TIMEOUT
,
false
);
}
...
...
core/store/dist/src/test/java/org/onlab/onos/store/flow/impl/ReplicaInfoManagerTest.java
View file @
07ac62a
...
...
@@ -5,6 +5,7 @@ import static org.junit.Assert.*;
import
java.util.Collections
;
import
java.util.Map
;
import
java.util.LinkedList
;
import
java.util.concurrent.CountDownLatch
;
import
java.util.concurrent.TimeUnit
;
...
...
@@ -12,6 +13,7 @@ import org.junit.After;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.onlab.onos.cluster.NodeId
;
import
org.onlab.onos.cluster.RoleInfo
;
import
org.onlab.onos.event.AbstractListenerRegistry
;
import
org.onlab.onos.event.DefaultEventSinkRegistry
;
import
org.onlab.onos.event.Event
;
...
...
@@ -87,7 +89,8 @@ public class ReplicaInfoManagerTest {
service
.
addListener
(
new
MasterNodeCheck
(
latch
,
DID1
,
NID1
));
// fake MastershipEvent
eventDispatcher
.
post
(
new
MastershipEvent
(
Type
.
MASTER_CHANGED
,
DID1
,
NID1
));
eventDispatcher
.
post
(
new
MastershipEvent
(
Type
.
MASTER_CHANGED
,
DID1
,
new
RoleInfo
(
NID1
,
new
LinkedList
<
NodeId
>())));
assertTrue
(
latch
.
await
(
1
,
TimeUnit
.
SECONDS
));
}
...
...
core/store/hz/cluster/src/main/java/org/onlab/onos/store/mastership/impl/DistributedMastershipStore.java
View file @
07ac62a
...
...
@@ -136,13 +136,13 @@ implements MastershipStore {
rv
.
reassign
(
nodeId
,
STANDBY
,
NONE
);
roleMap
.
put
(
deviceId
,
rv
);
updateTerm
(
deviceId
);
return
new
MastershipEvent
(
MASTER_CHANGED
,
deviceId
,
nodeId
);
return
new
MastershipEvent
(
MASTER_CHANGED
,
deviceId
,
rv
.
roleInfo
()
);
case
NONE:
rv
.
add
(
MASTER
,
nodeId
);
rv
.
reassign
(
nodeId
,
STANDBY
,
NONE
);
roleMap
.
put
(
deviceId
,
rv
);
updateTerm
(
deviceId
);
return
new
MastershipEvent
(
MASTER_CHANGED
,
deviceId
,
nodeId
);
return
new
MastershipEvent
(
MASTER_CHANGED
,
deviceId
,
rv
.
roleInfo
()
);
default
:
log
.
warn
(
"unknown Mastership Role {}"
,
role
);
return
null
;
...
...
@@ -306,7 +306,7 @@ implements MastershipStore {
roleMap
.
put
(
deviceId
,
rv
);
Integer
term
=
terms
.
get
(
deviceId
);
terms
.
put
(
deviceId
,
++
term
);
return
new
MastershipEvent
(
MASTER_CHANGED
,
deviceId
,
backup
);
return
new
MastershipEvent
(
MASTER_CHANGED
,
deviceId
,
rv
.
roleInfo
()
);
}
}
...
...
@@ -373,7 +373,7 @@ implements MastershipStore {
return
;
}
notifyDelegate
(
new
MastershipEvent
(
MASTER_CHANGED
,
event
.
getKey
(),
event
.
getValue
().
get
(
MASTER
)));
MASTER_CHANGED
,
event
.
getKey
(),
event
.
getValue
().
roleInfo
(
)));
}
@Override
...
...
core/store/hz/cluster/src/main/java/org/onlab/onos/store/mastership/impl/RoleValue.java
View file @
07ac62a
...
...
@@ -10,6 +10,9 @@ import org.onlab.onos.cluster.NodeId;
import
org.onlab.onos.cluster.RoleInfo
;
import
org.onlab.onos.net.MastershipRole
;
import
com.google.common.base.MoreObjects
;
import
com.google.common.base.MoreObjects.ToStringHelper
;
/**
* A structure that holds node mastership roles associated with a
* {@link DeviceId}. This structure needs to be locked through IMap.
...
...
@@ -109,14 +112,10 @@ public class RoleValue {
@Override
public
String
toString
()
{
final
StringBuilder
builder
=
new
StringBuilder
(
);
ToStringHelper
helper
=
MoreObjects
.
toStringHelper
(
this
.
getClass
()
);
for
(
Map
.
Entry
<
MastershipRole
,
List
<
NodeId
>>
el
:
value
.
entrySet
())
{
builder
.
append
(
el
.
getKey
().
toString
()).
append
(
": ["
);
for
(
NodeId
n
:
el
.
getValue
())
{
builder
.
append
(
n
);
}
builder
.
append
(
"]\n"
);
helper
.
add
(
el
.
getKey
().
toString
(),
el
.
getValue
());
}
return
build
er
.
toString
();
return
help
er
.
toString
();
}
}
...
...
core/store/trivial/src/main/java/org/onlab/onos/store/trivial/impl/SimpleMastershipStore.java
View file @
07ac62a
...
...
@@ -29,6 +29,8 @@ import org.onlab.onos.store.AbstractStore;
import
org.onlab.packet.IpPrefix
;
import
org.slf4j.Logger
;
import
com.google.common.collect.Lists
;
import
static
org
.
onlab
.
onos
.
mastership
.
MastershipEvent
.
Type
.*;
/**
...
...
@@ -89,7 +91,8 @@ public class SimpleMastershipStore
}
}
return
new
MastershipEvent
(
MASTER_CHANGED
,
deviceId
,
nodeId
);
return
new
MastershipEvent
(
MASTER_CHANGED
,
deviceId
,
new
RoleInfo
(
nodeId
,
Lists
.
newLinkedList
(
backups
)));
}
@Override
...
...
@@ -196,7 +199,8 @@ public class SimpleMastershipStore
}
else
{
masterMap
.
put
(
deviceId
,
backup
);
termMap
.
get
(
deviceId
).
incrementAndGet
();
return
new
MastershipEvent
(
MASTER_CHANGED
,
deviceId
,
backup
);
return
new
MastershipEvent
(
MASTER_CHANGED
,
deviceId
,
new
RoleInfo
(
backup
,
Lists
.
newLinkedList
(
backups
)));
}
case
STANDBY:
case
NONE:
...
...
providers/openflow/flow/src/main/java/org/onlab/onos/provider/of/flow/impl/FlowEntryBuilder.java
View file @
07ac62a
...
...
@@ -78,7 +78,7 @@ public class FlowEntryBuilder {
if
(
addedRule
)
{
FlowRule
rule
=
new
DefaultFlowRule
(
DeviceId
.
deviceId
(
Dpid
.
uri
(
dpid
)),
buildSelector
(),
buildTreatment
(),
stat
.
getPriority
(),
stat
.
getCookie
().
getValue
(),
stat
.
getIdleTimeout
());
stat
.
getCookie
().
getValue
(),
stat
.
getIdleTimeout
()
,
false
);
return
new
DefaultFlowEntry
(
rule
,
FlowEntryState
.
ADDED
,
stat
.
getDurationSec
(),
stat
.
getPacketCount
().
getValue
(),
stat
.
getByteCount
().
getValue
());
...
...
@@ -86,7 +86,7 @@ public class FlowEntryBuilder {
}
else
{
FlowRule
rule
=
new
DefaultFlowRule
(
DeviceId
.
deviceId
(
Dpid
.
uri
(
dpid
)),
buildSelector
(),
null
,
removed
.
getPriority
(),
removed
.
getCookie
().
getValue
(),
removed
.
getIdleTimeout
());
removed
.
getCookie
().
getValue
(),
removed
.
getIdleTimeout
()
,
false
);
return
new
DefaultFlowEntry
(
rule
,
FlowEntryState
.
REMOVED
,
removed
.
getDurationSec
(),
removed
.
getPacketCount
().
getValue
(),
removed
.
getByteCount
().
getValue
());
}
...
...
Please
register
or
login
to post a comment