Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
floodlight
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
croft1
floodlight
Commits
a4e05952
Commit
a4e05952
authored
12 years ago
by
Kanzhe Jiang
Browse files
Options
Downloads
Patches
Plain Diff
order the ofmessage listeners in mockFloodlightProvider
parent
9865f682
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/test/java/net/floodlightcontroller/core/test/MockFloodlightProvider.java
+60
-21
60 additions, 21 deletions
...loodlightcontroller/core/test/MockFloodlightProvider.java
with
60 additions
and
21 deletions
src/test/java/net/floodlightcontroller/core/test/MockFloodlightProvider.java
+
60
−
21
View file @
a4e05952
...
...
@@ -19,11 +19,14 @@ package net.floodlightcontroller.core.test;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ConcurrentMap
;
import
java.util.concurrent.CopyOnWriteArrayList
;
import
net.floodlightcontroller.core.FloodlightContext
;
...
...
@@ -39,19 +42,23 @@ import net.floodlightcontroller.core.module.FloodlightModuleContext;
import
net.floodlightcontroller.core.module.FloodlightModuleException
;
import
net.floodlightcontroller.core.module.IFloodlightModule
;
import
net.floodlightcontroller.core.module.IFloodlightService
;
import
net.floodlightcontroller.core.util.ListenerDispatcher
;
import
net.floodlightcontroller.packet.Ethernet
;
import
org.openflow.protocol.OFMessage
;
import
org.openflow.protocol.OFPacketIn
;
import
org.openflow.protocol.OFType
;
import
org.openflow.protocol.factory.BasicFactory
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
*
* @author David Erickson (daviderickson@cs.stanford.edu)
*/
public
class
MockFloodlightProvider
implements
IFloodlightModule
,
IFloodlightProviderService
{
protected
Map
<
OFType
,
List
<
IOFMessageListener
>>
listeners
;
protected
static
Logger
log
=
LoggerFactory
.
getLogger
(
MockFloodlightProvider
.
class
);
protected
ConcurrentMap
<
OFType
,
ListenerDispatcher
<
OFType
,
IOFMessageListener
>>
listeners
;
protected
List
<
IOFSwitchListener
>
switchListeners
;
protected
List
<
IHAListener
>
haListeners
;
protected
Map
<
Long
,
IOFSwitch
>
switches
;
...
...
@@ -61,36 +68,47 @@ public class MockFloodlightProvider implements IFloodlightModule, IFloodlightPro
*
*/
public
MockFloodlightProvider
()
{
listeners
=
new
ConcurrentHashMap
<
OFType
,
List
<
IOFMessageListener
>>();
listeners
=
new
ConcurrentHashMap
<
OFType
,
ListenerDispatcher
<
OFType
,
IOFMessageListener
>>();
switches
=
new
ConcurrentHashMap
<
Long
,
IOFSwitch
>();
switchListeners
=
new
CopyOnWriteArrayList
<
IOFSwitchListener
>();
haListeners
=
new
CopyOnWriteArrayList
<
IHAListener
>();
factory
=
new
BasicFactory
();
}
public
void
addOFMessageListener
(
OFType
type
,
IOFMessageListener
listener
)
{
if
(!
listeners
.
containsKey
(
type
))
{
listeners
.
put
(
type
,
new
ArrayList
<
IOFMessageListener
>());
@Override
public
synchronized
void
addOFMessageListener
(
OFType
type
,
IOFMessageListener
listener
)
{
ListenerDispatcher
<
OFType
,
IOFMessageListener
>
ldd
=
listeners
.
get
(
type
);
if
(
ldd
==
null
)
{
ldd
=
new
ListenerDispatcher
<
OFType
,
IOFMessageListener
>();
listeners
.
put
(
type
,
ldd
);
}
l
isteners
.
get
(
type
).
add
(
listener
);
l
dd
.
addListener
(
type
,
listener
);
}
public
void
removeOFMessageListener
(
OFType
type
,
IOFMessageListener
listener
)
{
listeners
.
get
(
type
).
remove
(
listener
);
@Override
public
synchronized
void
removeOFMessageListener
(
OFType
type
,
IOFMessageListener
listener
)
{
ListenerDispatcher
<
OFType
,
IOFMessageListener
>
ldd
=
listeners
.
get
(
type
);
if
(
ldd
!=
null
)
{
ldd
.
removeListener
(
listener
);
}
}
/**
* @return the listeners
*/
public
Map
<
OFType
,
List
<
IOFMessageListener
>>
getListeners
()
{
return
listeners
;
}
/**
* @param listeners the listeners to set
*/
public
void
setListeners
(
Map
<
OFType
,
List
<
IOFMessageListener
>>
listeners
)
{
this
.
listeners
=
listeners
;
Map
<
OFType
,
List
<
IOFMessageListener
>>
lers
=
new
HashMap
<
OFType
,
List
<
IOFMessageListener
>>();
for
(
Entry
<
OFType
,
ListenerDispatcher
<
OFType
,
IOFMessageListener
>>
e
:
listeners
.
entrySet
())
{
lers
.
put
(
e
.
getKey
(),
e
.
getValue
().
getOrderedListeners
());
}
return
Collections
.
unmodifiableMap
(
lers
);
}
public
void
clearListeners
()
{
...
...
@@ -121,10 +139,10 @@ public class MockFloodlightProvider implements IFloodlightModule, IFloodlightPro
}
public
void
dispatchMessage
(
IOFSwitch
sw
,
OFMessage
msg
,
FloodlightContext
bc
)
{
List
<
IOFMessageListener
>
l
isteners
=
this
.
listeners
.
get
(
msg
.
getType
());
if
(
l
isteners
!=
null
)
{
List
<
IOFMessageListener
>
theL
isteners
=
listeners
.
get
(
msg
.
getType
())
.
getOrderedListeners
()
;
if
(
theL
isteners
!=
null
)
{
Command
result
=
Command
.
CONTINUE
;
Iterator
<
IOFMessageListener
>
it
=
l
isteners
.
iterator
();
Iterator
<
IOFMessageListener
>
it
=
theL
isteners
.
iterator
();
if
(
OFType
.
PACKET_IN
.
equals
(
msg
.
getType
()))
{
OFPacketIn
pi
=
(
OFPacketIn
)
msg
;
Ethernet
eth
=
new
Ethernet
();
...
...
@@ -142,7 +160,7 @@ public class MockFloodlightProvider implements IFloodlightModule, IFloodlightPro
public
void
handleOutgoingMessage
(
IOFSwitch
sw
,
OFMessage
m
,
FloodlightContext
bc
)
{
List
<
IOFMessageListener
>
msgListeners
=
null
;
if
(
listeners
.
containsKey
(
m
.
getType
()))
{
msgListeners
=
listeners
.
get
(
m
.
getType
());
msgListeners
=
listeners
.
get
(
m
.
getType
())
.
getOrderedListeners
()
;
}
if
(
msgListeners
!=
null
)
{
...
...
@@ -195,7 +213,7 @@ public class MockFloodlightProvider implements IFloodlightModule, IFloodlightPro
@Override
public
void
run
()
{
// no-op
logListeners
();
}
@Override
...
...
@@ -302,4 +320,25 @@ public class MockFloodlightProvider implements IFloodlightModule, IFloodlightPro
return
0
;
}
private
void
logListeners
()
{
for
(
Map
.
Entry
<
OFType
,
ListenerDispatcher
<
OFType
,
IOFMessageListener
>>
entry
:
listeners
.
entrySet
())
{
OFType
type
=
entry
.
getKey
();
ListenerDispatcher
<
OFType
,
IOFMessageListener
>
ldd
=
entry
.
getValue
();
StringBuffer
sb
=
new
StringBuffer
();
sb
.
append
(
"OFListeners for "
);
sb
.
append
(
type
);
sb
.
append
(
": "
);
for
(
IOFMessageListener
l
:
ldd
.
getOrderedListeners
())
{
sb
.
append
(
l
.
getName
());
sb
.
append
(
","
);
}
log
.
debug
(
sb
.
toString
());
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment