Toggle navigation
Toggle navigation
This project
Loading...
Sign in
홍길동
/
onos
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Ayaka Koshibe
2014-09-22 17:11:47 -0700
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
fbf5fd39166a3e4552543369dd64d281dbc30b5f
fbf5fd39
2 parents
8d504a9a
ad4c1ee4
Merge branch 'master' of
ssh://gerrit.onlab.us:29418/onos-next
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
65 additions
and
25 deletions
core/api/src/main/java/org/onlab/onos/net/flow/DefaultFlowRule.java
core/net/src/main/java/org/onlab/onos/net/flow/impl/FlowRuleManager.java
core/net/src/test/java/org/onlab/onos/net/flow/impl/FlowRuleManagerTest.java
core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleFlowRuleStore.java
core/api/src/main/java/org/onlab/onos/net/flow/DefaultFlowRule.java
View file @
fbf5fd3
...
...
@@ -168,6 +168,7 @@ public class DefaultFlowRule implements FlowRule {
.
add
(
"selector"
,
selector
)
.
add
(
"treatment"
,
treatment
)
.
add
(
"created"
,
created
)
.
add
(
"state"
,
state
)
.
toString
();
}
...
...
core/net/src/main/java/org/onlab/onos/net/flow/impl/FlowRuleManager.java
View file @
fbf5fd3
...
...
@@ -84,8 +84,9 @@ implements FlowRuleService, FlowRuleProviderRegistry {
@Override
public
void
removeFlowRules
(
FlowRule
...
flowRules
)
{
FlowRule
f
;
for
(
int
i
=
0
;
i
<
flowRules
.
length
;
i
++)
{
FlowRule
f
=
new
DefaultFlowRule
(
flowRules
[
i
],
FlowRuleState
.
PENDING_REMOVE
);
f
=
new
DefaultFlowRule
(
flowRules
[
i
],
FlowRuleState
.
PENDING_REMOVE
);
final
Device
device
=
deviceService
.
getDevice
(
f
.
deviceId
());
final
FlowRuleProvider
frp
=
getProvider
(
device
.
providerId
());
store
.
deleteFlowRule
(
f
);
...
...
@@ -134,7 +135,7 @@ implements FlowRuleService, FlowRuleProviderRegistry {
public
void
flowMissing
(
FlowRule
flowRule
)
{
checkNotNull
(
flowRule
,
FLOW_RULE_NULL
);
checkValidity
();
log
.
info
(
"Flow {} has not been installed."
);
log
.
info
(
"Flow {} has not been installed."
,
flowRule
);
}
...
...
@@ -142,7 +143,7 @@ implements FlowRuleService, FlowRuleProviderRegistry {
public
void
extraneousFlow
(
FlowRule
flowRule
)
{
checkNotNull
(
flowRule
,
FLOW_RULE_NULL
);
checkValidity
();
log
.
info
(
"Flow {} is on switch but not in store."
);
log
.
info
(
"Flow {} is on switch but not in store."
,
flowRule
);
}
@Override
...
...
@@ -170,8 +171,8 @@ implements FlowRuleService, FlowRuleProviderRegistry {
@Override
public
void
pushFlowMetrics
(
DeviceId
deviceId
,
Iterable
<
FlowRule
>
flowEntries
)
{
List
<
FlowRule
>
storedRules
=
Lists
.
newLinkedList
(
store
.
getFlowEntries
(
deviceId
));
//List<FlowRule> switchRules = Lists.newLinkedList(flowEntries);
Iterator
<
FlowRule
>
switchRulesIterator
=
flowEntries
.
iterator
();
//switchRules.iterator();
Iterator
<
FlowRule
>
switchRulesIterator
=
flowEntries
.
iterator
();
while
(
switchRulesIterator
.
hasNext
())
{
FlowRule
rule
=
switchRulesIterator
.
next
();
...
...
core/net/src/test/java/org/onlab/onos/net/flow/impl/FlowRuleManagerTest.java
View file @
fbf5fd3
...
...
@@ -26,6 +26,7 @@ import org.onlab.onos.net.device.DeviceListener;
import
org.onlab.onos.net.device.DeviceService
;
import
org.onlab.onos.net.flow.DefaultFlowRule
;
import
org.onlab.onos.net.flow.FlowRule
;
import
org.onlab.onos.net.flow.FlowRule.FlowRuleState
;
import
org.onlab.onos.net.flow.FlowRuleEvent
;
import
org.onlab.onos.net.flow.FlowRuleListener
;
import
org.onlab.onos.net.flow.FlowRuleProvider
;
...
...
@@ -57,7 +58,7 @@ public class FlowRuleManagerTest {
protected
FlowRuleService
service
;
protected
FlowRuleProviderRegistry
registry
;
protected
FlowRuleProviderService
providerSer
iv
ce
;
protected
FlowRuleProviderService
providerSer
vi
ce
;
protected
TestProvider
provider
;
protected
TestListener
listener
=
new
TestListener
();
...
...
@@ -73,7 +74,7 @@ public class FlowRuleManagerTest {
mgr
.
activate
();
mgr
.
addListener
(
listener
);
provider
=
new
TestProvider
(
PID
);
providerSer
iv
ce
=
registry
.
register
(
provider
);
providerSer
vi
ce
=
registry
.
register
(
provider
);
assertTrue
(
"provider should be registered"
,
registry
.
getProviders
().
contains
(
provider
.
id
()));
}
...
...
@@ -95,10 +96,15 @@ public class FlowRuleManagerTest {
return
new
DefaultFlowRule
(
DID
,
ts
,
tr
,
0
);
}
private
void
addFlowRule
(
int
hval
)
{
private
FlowRule
flowRule
(
FlowRule
rule
,
FlowRuleState
state
)
{
return
new
DefaultFlowRule
(
rule
,
state
);
}
private
FlowRule
addFlowRule
(
int
hval
)
{
FlowRule
rule
=
flowRule
(
hval
,
hval
);
providerSer
iv
ce
.
flowAdded
(
rule
);
providerSer
vi
ce
.
flowAdded
(
rule
);
assertNotNull
(
"rule should be found"
,
service
.
getFlowEntries
(
DID
));
return
rule
;
}
private
void
validateEvents
(
FlowRuleEvent
.
Type
...
events
)
{
...
...
@@ -135,40 +141,53 @@ public class FlowRuleManagerTest {
validateEvents
(
RULE_UPDATED
);
}
//backing store is sensitive to the order of additions/removals
private
boolean
validateState
(
FlowRuleState
...
state
)
{
Iterable
<
FlowRule
>
rules
=
service
.
getFlowEntries
(
DID
);
int
i
=
0
;
for
(
FlowRule
f
:
rules
)
{
if
(
f
.
state
()
!=
state
[
i
])
{
return
false
;
}
i
++;
}
return
true
;
}
@Test
public
void
applyFlowRules
()
{
TestSelector
ts
=
new
TestSelector
(
1
);
FlowRule
r1
=
flowRule
(
1
,
1
);
FlowRule
r2
=
flowRule
(
1
,
2
);
FlowRule
r3
=
flowRule
(
1
,
3
);
//current FlowRules always return 0. FlowEntries inherit the value
FlowRule
e1
=
new
DefaultFlowRule
(
DID
,
ts
,
r1
.
treatment
(),
0
);
FlowRule
e2
=
new
DefaultFlowRule
(
DID
,
ts
,
r2
.
treatment
(),
0
);
FlowRule
e3
=
new
DefaultFlowRule
(
DID
,
ts
,
r3
.
treatment
(),
0
);
List
<
FlowRule
>
fel
=
Lists
.
newArrayList
(
e1
,
e2
,
e3
);
assertTrue
(
"store should be empty"
,
Sets
.
newHashSet
(
service
.
getFlowEntries
(
DID
)).
isEmpty
());
mgr
.
applyFlowRules
(
r1
,
r2
,
r3
);
assertEquals
(
"3 rules should exist"
,
3
,
flowCount
());
assertTrue
(
"3 entries should result"
,
fel
.
containsAll
(
Lists
.
newArrayList
(
r1
,
r2
,
r3
)));
assertTrue
(
"Entries should be pending add."
,
validateState
(
FlowRuleState
.
PENDING_ADD
,
FlowRuleState
.
PENDING_ADD
,
FlowRuleState
.
PENDING_ADD
));
}
@Test
public
void
removeFlowRules
()
{
addFlowRule
(
1
);
addFlowRule
(
2
);
FlowRule
f1
=
addFlowRule
(
1
);
FlowRule
f2
=
addFlowRule
(
2
);
addFlowRule
(
3
);
assertEquals
(
"3 rules should exist"
,
3
,
flowCount
());
validateEvents
(
RULE_ADDED
,
RULE_ADDED
,
RULE_ADDED
);
FlowRule
rem1
=
flowRule
(
1
,
1
);
FlowRule
rem2
=
flowRule
(
2
,
2
);
FlowRule
rem1
=
flowRule
(
f1
,
FlowRuleState
.
REMOVED
);
FlowRule
rem2
=
flowRule
(
f2
,
FlowRuleState
.
REMOVED
);
mgr
.
removeFlowRules
(
rem1
,
rem2
);
//removing from north, so no events generated
validateEvents
();
assertEquals
(
"3 rule should exist"
,
3
,
flowCount
());
assertTrue
(
"Entries should be pending remove."
,
validateState
(
FlowRuleState
.
CREATED
,
FlowRuleState
.
PENDING_REMOVE
,
FlowRuleState
.
PENDING_REMOVE
));
mgr
.
removeFlowRules
(
rem1
);
assertEquals
(
"3 rule should still exist"
,
3
,
flowCount
());
...
...
@@ -176,16 +195,34 @@ public class FlowRuleManagerTest {
@Test
public
void
flowRemoved
()
{
addFlowRule
(
1
);
FlowRule
f1
=
addFlowRule
(
1
);
addFlowRule
(
2
);
FlowRule
rem1
=
flowRule
(
1
,
1
);
providerSer
iv
ce
.
flowRemoved
(
rem1
);
FlowRule
rem1
=
flowRule
(
f1
,
FlowRuleState
.
REMOVED
);
providerSer
vi
ce
.
flowRemoved
(
rem1
);
validateEvents
(
RULE_ADDED
,
RULE_ADDED
,
RULE_REMOVED
);
providerSer
iv
ce
.
flowRemoved
(
rem1
);
providerSer
vi
ce
.
flowRemoved
(
rem1
);
validateEvents
();
}
@Test
public
void
flowMetrics
()
{
FlowRule
f1
=
flowRule
(
1
,
1
);
FlowRule
f2
=
flowRule
(
2
,
2
);
FlowRule
f3
=
flowRule
(
3
,
3
);
FlowRule
updatedF1
=
flowRule
(
f1
,
FlowRuleState
.
ADDED
);
FlowRule
updatedF2
=
flowRule
(
f2
,
FlowRuleState
.
ADDED
);
mgr
.
applyFlowRules
(
f1
,
f2
,
f3
);
providerService
.
pushFlowMetrics
(
DID
,
Lists
.
newArrayList
(
updatedF1
,
updatedF2
));
assertTrue
(
"Entries should be added."
,
validateState
(
FlowRuleState
.
PENDING_ADD
,
FlowRuleState
.
ADDED
,
FlowRuleState
.
ADDED
));
//TODO: add tests for flowmissing and extraneous flows
}
private
static
class
TestListener
implements
FlowRuleListener
{
final
List
<
FlowRuleEvent
>
events
=
new
ArrayList
<>();
...
...
core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleFlowRuleStore.java
View file @
fbf5fd3
...
...
@@ -60,6 +60,7 @@ public class SimpleFlowRuleStore implements FlowRuleStore {
* find the rule and mark it for deletion.
* Ultimately a flow removed will come remove it.
*/
if
(
flowEntries
.
containsEntry
(
did
,
rule
))
{
synchronized
(
flowEntries
)
{
...
...
Please
register
or
login
to post a comment