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-06 10:39:03 -0700
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
9b4030df2a37c7e919c1f19c82be4957e3729061
9b4030df
1 parent
95329ebc
Added a summary command.
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
121 additions
and
34 deletions
apps/ifwd/src/main/java/org/onlab/onos/ifwd/IntentReactiveForwarding.java
cli/src/main/java/org/onlab/onos/cli/SummaryCommand.java
cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleService.java
core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleStore.java
core/net/src/main/java/org/onlab/onos/net/flow/impl/FlowRuleManager.java
core/store/dist/src/main/java/org/onlab/onos/store/flow/impl/DistributedFlowRuleStore.java
core/store/hz/net/src/main/java/org/onlab/onos/store/flow/impl/DistributedFlowRuleStore.java
core/store/trivial/src/main/java/org/onlab/onos/store/trivial/impl/SimpleFlowRuleStore.java
apps/ifwd/src/main/java/org/onlab/onos/ifwd/IntentReactiveForwarding.java
View file @
9b4030d
...
...
@@ -14,6 +14,7 @@ import org.onlab.onos.net.flow.TrafficSelector;
import
org.onlab.onos.net.flow.TrafficTreatment
;
import
org.onlab.onos.net.host.HostService
;
import
org.onlab.onos.net.intent.HostToHostIntent
;
import
org.onlab.onos.net.intent.Intent
;
import
org.onlab.onos.net.intent.IntentId
;
import
org.onlab.onos.net.intent.IntentService
;
import
org.onlab.onos.net.packet.DefaultOutboundPacket
;
...
...
@@ -26,6 +27,9 @@ import org.onlab.onos.net.topology.TopologyService;
import
org.onlab.packet.Ethernet
;
import
org.slf4j.Logger
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
import
static
org
.
slf4j
.
LoggerFactory
.
getLogger
;
/**
...
...
@@ -52,6 +56,8 @@ public class IntentReactiveForwarding {
private
static
long
intentId
=
1
;
private
Map
<
HostIdPair
,
IntentId
>
intents
=
new
ConcurrentHashMap
<>();
@Activate
public
void
activate
()
{
packetService
.
addProcessor
(
processor
,
PacketProcessor
.
ADVISOR_MAX
+
2
);
...
...
@@ -91,8 +97,12 @@ public class IntentReactiveForwarding {
return
;
}
// Otherwise forward and be done with it.
setUpConnectivity
(
context
,
srcId
,
dstId
);
// Install a new intent only if we have not installed one already
HostIdPair
key
=
new
HostIdPair
(
srcId
,
dstId
);
if
(!
intents
.
containsKey
(
key
))
{
// Otherwise forward and be done with it.
intents
.
put
(
key
,
setUpConnectivity
(
context
,
srcId
,
dstId
).
getId
());
}
forwardPacketToDst
(
context
,
dst
);
}
}
...
...
@@ -122,15 +132,26 @@ public class IntentReactiveForwarding {
}
// Install a rule forwarding the packet to the specified port.
private
void
setUpConnectivity
(
PacketContext
context
,
HostId
srcId
,
HostId
dstId
)
{
private
Intent
setUpConnectivity
(
PacketContext
context
,
HostId
srcId
,
HostId
dstId
)
{
TrafficSelector
selector
=
DefaultTrafficSelector
.
builder
().
build
();
TrafficTreatment
treatment
=
DefaultTrafficTreatment
.
builder
().
build
();
HostToHostIntent
intent
=
new
HostToHostIntent
(
new
IntentId
(
intentId
++),
srcId
,
dstId
,
selector
,
treatment
);
intentService
.
submit
(
intent
);
return
intent
;
}
private
class
HostIdPair
{
HostId
one
;
HostId
two
;
HostIdPair
(
HostId
one
,
HostId
two
)
{
boolean
oneFirst
=
one
.
hashCode
()
<
two
.
hashCode
();
this
.
one
=
oneFirst
?
one
:
two
;
this
.
two
=
oneFirst
?
two
:
one
;
}
}
}
...
...
cli/src/main/java/org/onlab/onos/cli/SummaryCommand.java
0 → 100644
View file @
9b4030d
package
org
.
onlab
.
onos
.
cli
;
import
org.apache.karaf.shell.commands.Command
;
import
org.onlab.onos.cluster.ClusterService
;
import
org.onlab.onos.net.device.DeviceService
;
import
org.onlab.onos.net.flow.FlowRuleService
;
import
org.onlab.onos.net.host.HostService
;
import
org.onlab.onos.net.intent.IntentService
;
import
org.onlab.onos.net.link.LinkService
;
import
org.onlab.onos.net.topology.TopologyService
;
/**
* Provides summary of ONOS model.
*/
@Command
(
scope
=
"onos"
,
name
=
"summary"
,
description
=
"Provides summary of ONOS model"
)
public
class
SummaryCommand
extends
AbstractShellCommand
{
@Override
protected
void
execute
()
{
TopologyService
topologyService
=
get
(
TopologyService
.
class
);
print
(
"nodes=%d, devices=%d, links=%d, hosts=%d, clusters=%s, flows=%d, intents=%d"
,
get
(
ClusterService
.
class
).
getNodes
().
size
(),
get
(
DeviceService
.
class
).
getDeviceCount
(),
get
(
LinkService
.
class
).
getLinkCount
(),
get
(
HostService
.
class
).
getHostCount
(),
topologyService
.
getClusters
(
topologyService
.
currentTopology
()).
size
(),
get
(
FlowRuleService
.
class
).
getFlowRuleCount
(),
get
(
IntentService
.
class
).
getIntentCount
());
}
}
cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
View file @
9b4030d
...
...
@@ -2,6 +2,9 @@
<command-bundle
xmlns=
"http://karaf.apache.org/xmlns/shell/v1.1.0"
>
<command>
<action
class=
"org.onlab.onos.cli.SummaryCommand"
/>
</command>
<command>
<action
class=
"org.onlab.onos.cli.NodesListCommand"
/>
</command>
<command>
...
...
core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleService.java
View file @
9b4030d
...
...
@@ -13,6 +13,13 @@ import org.onlab.onos.net.DeviceId;
public
interface
FlowRuleService
{
/**
* Returns the number of flow rules in the system.
*
* @return flow rule count
*/
int
getFlowRuleCount
();
/**
* Returns the collection of flow entries applied on the specified device.
* This will include flow rules which may not yet have been applied to
* the device.
...
...
@@ -72,7 +79,4 @@ public interface FlowRuleService {
* @param listener flow rule listener
*/
void
removeListener
(
FlowRuleListener
listener
);
}
...
...
core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleStore.java
View file @
9b4030d
...
...
@@ -10,7 +10,15 @@ import org.onlab.onos.store.Store;
public
interface
FlowRuleStore
extends
Store
<
FlowRuleEvent
,
FlowRuleStoreDelegate
>
{
/**
* Returns the number of flow rule in the store.
*
* @return number of flow rules
*/
int
getFlowRuleCount
();
/**
* Returns the stored flow.
*
* @param rule the rule to look for
* @return a flow rule
*/
...
...
@@ -60,5 +68,4 @@ public interface FlowRuleStore extends Store<FlowRuleEvent, FlowRuleStoreDelegat
* @return flow_removed event, or null if nothing removed
*/
FlowRuleEvent
removeFlowRule
(
FlowEntry
rule
);
}
...
...
core/net/src/main/java/org/onlab/onos/net/flow/impl/FlowRuleManager.java
View file @
9b4030d
...
...
@@ -40,14 +40,14 @@ import com.google.common.collect.Lists;
@Component
(
immediate
=
true
)
@Service
public
class
FlowRuleManager
extends
AbstractProviderRegistry
<
FlowRuleProvider
,
FlowRuleProviderService
>
implements
FlowRuleService
,
FlowRuleProviderRegistry
{
extends
AbstractProviderRegistry
<
FlowRuleProvider
,
FlowRuleProviderService
>
implements
FlowRuleService
,
FlowRuleProviderRegistry
{
public
static
final
String
FLOW_RULE_NULL
=
"FlowRule cannot be null"
;
private
final
Logger
log
=
getLogger
(
getClass
());
private
final
AbstractListenerRegistry
<
FlowRuleEvent
,
FlowRuleListener
>
listenerRegistry
=
new
AbstractListenerRegistry
<>();
listenerRegistry
=
new
AbstractListenerRegistry
<>();
private
final
FlowRuleStoreDelegate
delegate
=
new
InternalStoreDelegate
();
...
...
@@ -75,6 +75,11 @@ implements FlowRuleService, FlowRuleProviderRegistry {
}
@Override
public
int
getFlowRuleCount
()
{
return
store
.
getFlowRuleCount
();
}
@Override
public
Iterable
<
FlowEntry
>
getFlowEntries
(
DeviceId
deviceId
)
{
return
store
.
getFlowEntries
(
deviceId
);
}
...
...
@@ -106,7 +111,7 @@ implements FlowRuleService, FlowRuleProviderRegistry {
@Override
public
void
removeFlowRulesById
(
ApplicationId
id
)
{
Iterable
<
FlowRule
>
rules
=
getFlowRulesById
(
id
);
Iterable
<
FlowRule
>
rules
=
getFlowRulesById
(
id
);
FlowRuleProvider
frp
;
Device
device
;
...
...
@@ -140,8 +145,8 @@ implements FlowRuleService, FlowRuleProviderRegistry {
}
private
class
InternalFlowRuleProviderService
extends
AbstractProviderService
<
FlowRuleProvider
>
implements
FlowRuleProviderService
{
extends
AbstractProviderService
<
FlowRuleProvider
>
implements
FlowRuleProviderService
{
protected
InternalFlowRuleProviderService
(
FlowRuleProvider
provider
)
{
super
(
provider
);
...
...
@@ -160,16 +165,16 @@ implements FlowRuleService, FlowRuleProviderRegistry {
FlowRuleProvider
frp
=
getProvider
(
device
.
providerId
());
FlowRuleEvent
event
=
null
;
switch
(
stored
.
state
())
{
case
ADDED:
case
PENDING_ADD:
case
ADDED:
case
PENDING_ADD:
frp
.
applyFlowRule
(
stored
);
break
;
case
PENDING_REMOVE:
case
REMOVED:
event
=
store
.
removeFlowRule
(
stored
);
break
;
default
:
break
;
break
;
case
PENDING_REMOVE:
case
REMOVED:
event
=
store
.
removeFlowRule
(
stored
);
break
;
default
:
break
;
}
if
(
event
!=
null
)
{
...
...
@@ -186,17 +191,17 @@ implements FlowRuleService, FlowRuleProviderRegistry {
FlowRuleProvider
frp
=
getProvider
(
device
.
providerId
());
FlowRuleEvent
event
=
null
;
switch
(
flowRule
.
state
())
{
case
PENDING_REMOVE:
case
REMOVED:
event
=
store
.
removeFlowRule
(
flowRule
);
frp
.
removeFlowRule
(
flowRule
);
break
;
case
ADDED:
case
PENDING_ADD:
frp
.
applyFlowRule
(
flowRule
);
break
;
default
:
log
.
debug
(
"Flow {} has not been installed."
,
flowRule
);
case
PENDING_REMOVE:
case
REMOVED:
event
=
store
.
removeFlowRule
(
flowRule
);
frp
.
removeFlowRule
(
flowRule
);
break
;
case
ADDED:
case
PENDING_ADD:
frp
.
applyFlowRule
(
flowRule
);
break
;
default
:
log
.
debug
(
"Flow {} has not been installed."
,
flowRule
);
}
if
(
event
!=
null
)
{
...
...
core/store/dist/src/main/java/org/onlab/onos/store/flow/impl/DistributedFlowRuleStore.java
View file @
9b4030d
...
...
@@ -58,6 +58,11 @@ public class DistributedFlowRuleStore
@Override
public
int
getFlowRuleCount
()
{
return
flowEntries
.
size
();
}
@Override
public
synchronized
FlowEntry
getFlowEntry
(
FlowRule
rule
)
{
for
(
FlowEntry
f
:
flowEntries
.
get
(
rule
.
deviceId
()))
{
if
(
f
.
equals
(
rule
))
{
...
...
core/store/hz/net/src/main/java/org/onlab/onos/store/flow/impl/DistributedFlowRuleStore.java
View file @
9b4030d
...
...
@@ -58,6 +58,11 @@ public class DistributedFlowRuleStore
@Override
public
int
getFlowRuleCount
()
{
return
flowEntries
.
size
();
}
@Override
public
synchronized
FlowEntry
getFlowEntry
(
FlowRule
rule
)
{
for
(
FlowEntry
f
:
flowEntries
.
get
(
rule
.
deviceId
()))
{
if
(
f
.
equals
(
rule
))
{
...
...
core/store/trivial/src/main/java/org/onlab/onos/store/trivial/impl/SimpleFlowRuleStore.java
View file @
9b4030d
...
...
@@ -57,6 +57,11 @@ public class SimpleFlowRuleStore
@Override
public
int
getFlowRuleCount
()
{
return
flowEntries
.
size
();
}
@Override
public
synchronized
FlowEntry
getFlowEntry
(
FlowRule
rule
)
{
for
(
FlowEntry
f
:
flowEntries
.
get
(
rule
.
deviceId
()))
{
if
(
f
.
equals
(
rule
))
{
...
...
Please
register
or
login
to post a comment