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
alshabib
2014-09-15 15:56:42 -0700
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
030111edc9547ece308e5f89a3921570d692c67e
030111ed
1 parent
025e09f0
sample app launched
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
121 additions
and
37 deletions
apps/fwd/src/main/java/org/onlab/onos/fwd/ReactiveForwarding.java
core/trivial/src/main/java/org/onlab/onos/net/trivial/packet/impl/ReactivePacketProcessor.java → apps/fwd/src/main/java/org/onlab/onos/fwd/ReactivePacketProcessor.java
apps/pom.xml
core/api/src/main/java/org/onlab/onos/net/flow/DefaultTrafficTreatment.java
core/api/src/main/java/org/onlab/onos/net/flow/Instruction.java
core/api/src/main/java/org/onlab/onos/net/flow/Instructions.java
core/api/src/main/java/org/onlab/onos/net/packet/DefaultPacketContext.java
core/api/src/main/java/org/onlab/onos/net/packet/PacketContext.java
core/api/src/test/java/org/onlab/onos/event/AbstractEventAccumulatorTest.java
core/trivial/src/main/java/org/onlab/onos/net/trivial/packet/impl/SimplePacketManager.java
features/features.xml
providers/of/packet/src/main/java/org/onlab/onos/provider/of/packet/impl/OpenFlowCorePacketContext.java
apps/fwd/src/main/java/org/onlab/onos/fwd/ReactiveForwarding.java
0 → 100644
View file @
030111e
package
org
.
onlab
.
onos
.
fwd
;
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.Reference
;
import
org.apache.felix.scr.annotations.ReferenceCardinality
;
import
org.onlab.onos.net.packet.PacketProcessor
;
import
org.onlab.onos.net.packet.PacketService
;
import
org.onlab.onos.net.topology.TopologyService
;
@Component
public
class
ReactiveForwarding
{
@Reference
(
cardinality
=
ReferenceCardinality
.
MANDATORY_UNARY
)
protected
TopologyService
topologyService
;
@Reference
(
cardinality
=
ReferenceCardinality
.
MANDATORY_UNARY
)
protected
PacketService
packetService
;
private
ReactivePacketProcessor
processor
;
@Activate
public
void
activate
()
{
processor
=
new
ReactivePacketProcessor
(
topologyService
);
packetService
.
addProcessor
(
processor
,
PacketProcessor
.
ADVISOR_MAX
+
1
);
}
@Deactivate
public
void
deactivate
()
{
packetService
.
removeProcessor
(
processor
);
processor
=
null
;
}
}
core/trivial/src/main/java/org/onlab/onos/net/trivial/packet/impl
/ReactivePacketProcessor.java
→
apps/fwd/src/main/java/org/onlab/onos/fwd
/ReactivePacketProcessor.java
View file @
030111e
package
org
.
onlab
.
onos
.
net
.
trivial
.
packet
.
impl
;
package
org
.
onlab
.
onos
.
fwd
;
import
static
org
.
slf4j
.
LoggerFactory
.
getLogger
;
...
...
@@ -6,16 +6,32 @@ import org.onlab.onos.net.PortNumber;
import
org.onlab.onos.net.flow.Instructions
;
import
org.onlab.onos.net.packet.PacketContext
;
import
org.onlab.onos.net.packet.PacketProcessor
;
import
org.onlab.onos.net.topology.TopologyService
;
import
org.slf4j.Logger
;
public
class
ReactivePacketProcessor
implements
PacketProcessor
{
private
final
Logger
log
=
getLogger
(
getClass
());
private
final
TopologyService
topologyService
;
public
ReactivePacketProcessor
(
TopologyService
topologyService
)
{
this
.
topologyService
=
topologyService
;
}
@Override
public
void
process
(
PacketContext
context
)
{
boolean
canBcast
=
topologyService
.
isBroadcastPoint
(
topologyService
.
currentTopology
(),
context
.
inPacket
().
receivedFrom
());
if
(
canBcast
)
{
context
.
treatmentBuilder
().
add
(
Instructions
.
createOutput
(
PortNumber
.
FLOOD
));
context
.
send
();
}
else
{
context
.
block
();
}
}
}
...
...
apps/pom.xml
View file @
030111e
...
...
@@ -18,6 +18,7 @@
<modules>
<module>
tvue
</module>
<module>
fwd
</module>
</modules>
<properties>
...
...
core/api/src/main/java/org/onlab/onos/net/flow/DefaultTrafficTreatment.java
View file @
030111e
...
...
@@ -6,7 +6,6 @@ import java.util.Collections;
import
java.util.LinkedList
;
import
java.util.List
;
import
org.onlab.onos.net.PortNumber
;
import
org.slf4j.Logger
;
@SuppressWarnings
(
"rawtypes"
)
...
...
@@ -33,29 +32,33 @@ public class DefaultTrafficTreatment implements TrafficTreatment {
private
final
Logger
log
=
getLogger
(
getClass
());
List
<
Instruction
<
PortNumber
>>
outputs
=
new
LinkedList
<>();
boolean
drop
=
false
;
List
<
Instruction
>
outputs
=
new
LinkedList
<>();
// TODO: should be a list of instructions based on group objects
List
<
Instruction
<
Object
>
>
groups
=
new
LinkedList
<>();
List
<
Instruction
>
groups
=
new
LinkedList
<>();
// TODO: should be a list of instructions based on modification objects
List
<
Instruction
<
Object
>
>
modifications
=
new
LinkedList
<>();
List
<
Instruction
>
modifications
=
new
LinkedList
<>();
@SuppressWarnings
(
"unchecked"
)
@Override
public
Builder
add
(
Instruction
instruction
)
{
switch
(
instruction
.
type
())
{
case
OUTPUT:
case
DROP:
// TODO: should check that there is only one drop instruction.
drop
=
true
;
break
;
case
OUTPUT:
outputs
.
add
(
instruction
);
break
;
case
MODIFICATION:
// TODO: enforce modification order if any
modifications
.
add
(
instruction
);
break
;
case
GROUP:
groups
.
add
(
instruction
);
break
;
default
:
log
.
warn
(
"Unknown instruction type {}"
,
instruction
.
type
());
}
...
...
@@ -64,10 +67,14 @@ public class DefaultTrafficTreatment implements TrafficTreatment {
@Override
public
TrafficTreatment
build
()
{
//If we are dropping should we just return an emptry list?
List
<
Instruction
>
instructions
=
new
LinkedList
<
Instruction
>();
instructions
.
addAll
(
modifications
);
instructions
.
addAll
(
groups
);
if
(!
drop
)
{
instructions
.
addAll
(
outputs
);
}
return
new
DefaultTrafficTreatment
(
instructions
);
}
...
...
core/api/src/main/java/org/onlab/onos/net/flow/Instruction.java
View file @
030111e
...
...
@@ -4,7 +4,7 @@ package org.onlab.onos.net.flow;
* Abstraction of a single traffic treatment step.
* @param <T> the type parameter for the instruction
*/
public
interface
Instruction
<
T
>
{
public
interface
Instruction
{
/**
* Represents the type of traffic treatment.
...
...
@@ -41,10 +41,4 @@ public interface Instruction<T> {
*/
public
Type
type
();
/**
* Returns the actual value of the instruction.
* @return the value for this instruction
*/
public
T
instruction
();
}
...
...
core/api/src/main/java/org/onlab/onos/net/flow/Instructions.java
View file @
030111e
package
org
.
onlab
.
onos
.
net
.
flow
;
import
org.onlab.onos.net.PortNumber
;
import
static
com
.
google
.
common
.
base
.
Preconditions
.
checkNotNull
;
import
org.onlab.onos.net.PortNumber
;
/**
* Factory class for creating various traffic treatment instructions.
*/
...
...
@@ -17,22 +18,44 @@ public final class Instructions {
* @param number port number
* @return output instruction
*/
public
static
Instruction
<
PortNumber
>
createOutput
(
final
PortNumber
number
)
{
return
new
Instruction
<
PortNumber
>()
{
public
static
OutputInstruction
createOutput
(
final
PortNumber
number
)
{
checkNotNull
(
number
,
"PortNumber cannot be null"
);
return
new
OutputInstruction
(
number
);
}
@Override
public
Instruction
.
Type
type
()
{
return
Type
.
OUTPUT
;
public
static
DropInstruction
createDrop
()
{
return
new
DropInstruction
();
}
// TODO: add create methods
public
static
final
class
DropInstruction
implements
Instruction
{
@Override
public
PortNumber
instruction
()
{
return
number
;
public
Type
type
()
{
return
Type
.
DROP
;
}
}
};
public
static
final
class
OutputInstruction
implements
Instruction
{
private
final
PortNumber
port
;
private
OutputInstruction
(
PortNumber
port
)
{
this
.
port
=
port
;
}
// TODO: add create methods
public
PortNumber
port
()
{
return
port
;
}
@Override
public
Type
type
()
{
return
Type
.
OUTPUT
;
}
}
}
...
...
core/api/src/main/java/org/onlab/onos/net/packet/DefaultPacketContext.java
View file @
030111e
...
...
@@ -51,7 +51,7 @@ public abstract class DefaultPacketContext implements PacketContext {
public
abstract
void
send
();
@Override
public
boolean
block
ed
()
{
public
boolean
block
()
{
return
this
.
block
.
getAndSet
(
true
);
}
...
...
core/api/src/main/java/org/onlab/onos/net/packet/PacketContext.java
View file @
030111e
...
...
@@ -45,7 +45,7 @@ public interface PacketContext {
* Blocks the outbound packet from being sent from this point onward.
* @return whether the outbound packet is blocked.
*/
boolean
block
ed
();
boolean
block
();
/**
* Check whether the outbound packet is blocked.
...
...
core/api/src/test/java/org/onlab/onos/event/AbstractEventAccumulatorTest.java
View file @
030111e
package
org
.
onlab
.
onos
.
event
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
onlab
.
junit
.
TestTools
.
delay
;
import
static
org
.
onlab
.
onos
.
event
.
TestEvent
.
Type
.
FOO
;
import
java.util.List
;
import
java.util.Timer
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
onlab
.
junit
.
TestTools
.
delay
;
import
static
org
.
onlab
.
onos
.
event
.
TestEvent
.
Type
.
FOO
;
import
org.junit.Test
;
/**
* Tests the operation of the accumulator.
...
...
core/trivial/src/main/java/org/onlab/onos/net/trivial/packet/impl/SimplePacketManager.java
View file @
030111e
package
org
.
onlab
.
onos
.
net
.
trivial
.
packet
.
impl
;
import
static
com
.
google
.
common
.
base
.
Preconditions
.
checkNotNull
;
import
static
org
.
slf4j
.
LoggerFactory
.
getLogger
;
import
java.util.Map
;
...
...
@@ -42,22 +43,20 @@ implements PacketService, PacketProviderRegistry {
private
final
Map
<
Integer
,
PacketProcessor
>
processors
=
new
TreeMap
<>();
private
final
PacketProcessor
reactiveProcessor
=
new
ReactivePacketProcessor
();
@Activate
public
void
activate
()
{
addProcessor
(
reactiveProcessor
,
PacketProcessor
.
ADVISOR_MAX
+
1
);
log
.
info
(
"Started"
);
}
@Deactivate
public
void
deactivate
()
{
removeProcessor
(
reactiveProcessor
);
log
.
info
(
"Stopped"
);
}
@Override
public
void
addProcessor
(
PacketProcessor
processor
,
int
priority
)
{
checkNotNull
(
processor
,
"Processor cannot be null"
);
processors
.
put
(
priority
,
processor
);
}
...
...
features/features.xml
View file @
030111e
...
...
@@ -79,4 +79,11 @@
<bundle>
mvn:org.onlab.onos/onos-app-tvue/1.0.0-SNAPSHOT
</bundle>
</feature>
<feature
name=
"onos-app-fwd"
version=
"1.0.0"
description=
"ONOS sample forwarding application"
>
<feature>
onos-core
</feature>
<bundle>
mvn:org.onlab.onos/onos-app-fwd/1.0.0-SNAPSHOT
</bundle>
</feature>
</features>
...
...
providers/of/packet/src/main/java/org/onlab/onos/provider/of/packet/impl/OpenFlowCorePacketContext.java
View file @
030111e
...
...
@@ -7,6 +7,7 @@ import java.util.List;
import
org.onlab.onos.net.PortNumber
;
import
org.onlab.onos.net.flow.Instruction
;
import
org.onlab.onos.net.flow.Instruction.Type
;
import
org.onlab.onos.net.flow.Instructions.OutputInstruction
;
import
org.onlab.onos.net.packet.DefaultPacketContext
;
import
org.onlab.onos.net.packet.InboundPacket
;
import
org.onlab.onos.net.packet.OutboundPacket
;
...
...
@@ -29,7 +30,7 @@ public class OpenFlowCorePacketContext extends DefaultPacketContext {
@Override
public
void
send
()
{
if
(!
this
.
block
ed
())
{
if
(!
this
.
block
())
{
if
(
outPacket
()
==
null
)
{
sendBufferedPacket
();
}
else
{
...
...
@@ -42,14 +43,13 @@ public class OpenFlowCorePacketContext extends DefaultPacketContext {
}
}
@SuppressWarnings
({
"rawtypes"
,
"unchecked"
})
private
void
sendBufferedPacket
()
{
List
<
Instruction
>
ins
=
treatmentBuilder
().
build
().
instructions
();
OFPort
p
=
null
;
//TODO: support arbitrary list of treatments
for
(
Instruction
i
:
ins
)
{
if
(
i
.
type
()
==
Type
.
OUTPUT
)
{
p
=
buildPort
(((
Instruction
<
PortNumber
>)
i
).
instruction
());
p
=
buildPort
(((
OutputInstruction
)
i
).
port
());
break
;
//for now...
}
}
...
...
Please
register
or
login
to post a comment