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-15 18:30:31 -0700
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
c16656fc67278619a6bf72ced80983ac289f6a50
c16656fc
1 parent
5fa3dc09
Added ability to configure reactive forwarding.
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
14 deletions
apps/fwd/pom.xml
apps/fwd/src/main/java/org/onlab/onos/fwd/ReactiveForwarding.java
pom.xml
apps/fwd/pom.xml
View file @
c16656f
...
...
@@ -16,4 +16,11 @@
<description>
ONOS simple reactive forwarding app
</description>
<dependencies>
<dependency>
<groupId>
org.osgi
</groupId>
<artifactId>
org.osgi.compendium
</artifactId>
</dependency>
</dependencies>
</project>
...
...
apps/fwd/src/main/java/org/onlab/onos/fwd/ReactiveForwarding.java
View file @
c16656f
package
org
.
onlab
.
onos
.
fwd
;
import
static
org
.
slf4j
.
LoggerFactory
.
getLogger
;
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
;
import
org.apache.felix.scr.annotations.Modified
;
import
org.apache.felix.scr.annotations.Property
;
import
org.apache.felix.scr.annotations.Reference
;
import
org.apache.felix.scr.annotations.ReferenceCardinality
;
import
org.onlab.onos.ApplicationId
;
...
...
@@ -29,8 +27,14 @@ import org.onlab.onos.net.packet.PacketProcessor;
import
org.onlab.onos.net.packet.PacketService
;
import
org.onlab.onos.net.topology.TopologyService
;
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.
*/
...
...
@@ -61,6 +65,9 @@ public class ReactiveForwarding {
private
ApplicationId
appId
;
@Property
(
name
=
"enabled"
,
boolValue
=
true
,
label
=
"Forwarding enabled"
)
private
boolean
isEnabled
=
true
;
@Activate
public
void
activate
()
{
appId
=
coreService
.
registerApplication
(
"org.onlab.onos.fwd"
);
...
...
@@ -76,6 +83,21 @@ public class ReactiveForwarding {
log
.
info
(
"Stopped"
);
}
@Modified
public
void
modified
(
ComponentContext
context
)
{
Dictionary
properties
=
context
.
getProperties
();
String
flag
=
(
String
)
properties
.
get
(
"enabled"
);
if
(
flag
!=
null
)
{
boolean
enabled
=
flag
.
equals
(
"true"
);
if
(
isEnabled
!=
enabled
)
{
isEnabled
=
enabled
;
if
(!
isEnabled
)
{
flowRuleService
.
removeFlowRulesById
(
appId
);
}
log
.
info
(
"Reconfigured enabled = {}"
,
isEnabled
);
}
}
}
/**
* Packet processor responsible for forwarding packets along their paths.
...
...
@@ -86,7 +108,7 @@ public class ReactiveForwarding {
public
void
process
(
PacketContext
context
)
{
// Stop processing if the packet has been handled, since we
// can't do any more to it.
if
(
context
.
isHandled
())
{
if
(
!
isEnabled
||
context
.
isHandled
())
{
return
;
}
...
...
@@ -114,8 +136,8 @@ public class ReactiveForwarding {
// Otherwise, get a set of paths that lead from here to the
// destination edge switch.
Set
<
Path
>
paths
=
topologyService
.
getPaths
(
topologyService
.
currentTopology
(),
pkt
.
receivedFrom
().
deviceId
(),
dst
.
location
().
deviceId
());
pkt
.
receivedFrom
().
deviceId
(),
dst
.
location
().
deviceId
());
if
(
paths
.
isEmpty
())
{
// If there are no paths, flood and bail.
flood
(
context
);
...
...
@@ -127,8 +149,8 @@ public class ReactiveForwarding {
Path
path
=
pickForwardPath
(
paths
,
pkt
.
receivedFrom
().
port
());
if
(
path
==
null
)
{
log
.
warn
(
"Doh... don't know where to go... {} -> {} received on {}"
,
ethPkt
.
getSourceMAC
(),
ethPkt
.
getDestinationMAC
(),
pkt
.
receivedFrom
());
ethPkt
.
getSourceMAC
(),
ethPkt
.
getDestinationMAC
(),
pkt
.
receivedFrom
());
flood
(
context
);
return
;
}
...
...
@@ -152,7 +174,7 @@ public class ReactiveForwarding {
// Floods the specified packet if permissible.
private
void
flood
(
PacketContext
context
)
{
if
(
topologyService
.
isBroadcastPoint
(
topologyService
.
currentTopology
(),
context
.
inPacket
().
receivedFrom
()))
{
context
.
inPacket
().
receivedFrom
()))
{
packetOut
(
context
,
PortNumber
.
FLOOD
);
}
else
{
context
.
block
();
...
...
@@ -174,15 +196,15 @@ public class ReactiveForwarding {
Ethernet
inPkt
=
context
.
inPacket
().
parsed
();
TrafficSelector
.
Builder
builder
=
DefaultTrafficSelector
.
builder
();
builder
.
matchEthType
(
inPkt
.
getEtherType
())
.
matchEthSrc
(
inPkt
.
getSourceMAC
())
.
matchEthDst
(
inPkt
.
getDestinationMAC
())
.
matchInport
(
context
.
inPacket
().
receivedFrom
().
port
());
.
matchEthSrc
(
inPkt
.
getSourceMAC
())
.
matchEthDst
(
inPkt
.
getDestinationMAC
())
.
matchInport
(
context
.
inPacket
().
receivedFrom
().
port
());
TrafficTreatment
.
Builder
treat
=
DefaultTrafficTreatment
.
builder
();
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
);
flowRuleService
.
applyFlowRules
(
f
);
...
...
pom.xml
View file @
c16656f
...
...
@@ -164,6 +164,12 @@
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
org.osgi
</groupId>
<artifactId>
org.osgi.compendium
</artifactId>
<version>
4.3.1
</version>
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
org.apache.felix
</groupId>
<artifactId>
org.apache.felix.scr.annotations
</artifactId>
<version>
1.9.8
</version>
...
...
Please
register
or
login
to post a comment