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-09-19 13:05:04 -0700
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
70b2e48b7cc3b6b2513c473c591d333f341f1c20
70b2e48b
2 parents
ab0af290
91c9bc71
Merge remote-tracking branch 'origin/master'
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
2 deletions
openflow/api/src/main/java/org/onlab/onos/openflow/controller/OpenFlowPacketContext.java
providers/openflow/packet/src/main/java/org/onlab/onos/provider/of/packet/impl/OpenFlowPacketProvider.java
providers/openflow/packet/src/test/java/org/onlab/onos/provider/of/packet/impl/OpenFlowPacketProviderTest.java
openflow/api/src/main/java/org/onlab/onos/openflow/controller/OpenFlowPacketContext.java
View file @
70b2e48
...
...
@@ -5,8 +5,9 @@ import org.projectfloodlight.openflow.types.OFPort;
/**
* A representation of a packet context which allows any provider
* to view the packet in event but may block the response to the
* event if blocked has been called.
* to view a packet in event, but may block the response to the
* event if blocked has been called. This packet context can be used
* to react to the packet in event with a packet out.
*/
public
interface
OpenFlowPacketContext
{
...
...
providers/openflow/packet/src/main/java/org/onlab/onos/provider/of/packet/impl/OpenFlowPacketProvider.java
View file @
70b2e48
...
...
@@ -3,6 +3,7 @@ package org.onlab.onos.provider.of.packet.impl;
import
static
org
.
slf4j
.
LoggerFactory
.
getLogger
;
import
java.nio.ByteBuffer
;
import
java.util.Collections
;
import
org.apache.felix.scr.annotations.Activate
;
import
org.apache.felix.scr.annotations.Component
;
...
...
@@ -12,6 +13,8 @@ import org.apache.felix.scr.annotations.ReferenceCardinality;
import
org.onlab.onos.net.ConnectPoint
;
import
org.onlab.onos.net.DeviceId
;
import
org.onlab.onos.net.PortNumber
;
import
org.onlab.onos.net.flow.instructions.Instruction
;
import
org.onlab.onos.net.flow.instructions.Instructions.OutputInstruction
;
import
org.onlab.onos.net.packet.DefaultInboundPacket
;
import
org.onlab.onos.net.packet.OutboundPacket
;
import
org.onlab.onos.net.packet.PacketProvider
;
...
...
@@ -22,9 +25,20 @@ import org.onlab.onos.net.provider.ProviderId;
import
org.onlab.onos.openflow.controller.Dpid
;
import
org.onlab.onos.openflow.controller.OpenFlowController
;
import
org.onlab.onos.openflow.controller.OpenFlowPacketContext
;
import
org.onlab.onos.openflow.controller.OpenFlowSwitch
;
import
org.onlab.onos.openflow.controller.PacketListener
;
import
org.onlab.packet.Ethernet
;
import
org.projectfloodlight.openflow.protocol.OFPacketOut
;
import
org.projectfloodlight.openflow.protocol.OFPortDesc
;
import
org.projectfloodlight.openflow.protocol.action.OFAction
;
import
org.projectfloodlight.openflow.protocol.ver10.OFFactoryVer10
;
import
org.projectfloodlight.openflow.types.OFBufferId
;
import
org.projectfloodlight.openflow.types.OFPort
;
import
org.slf4j.Logger
;
import
static
org
.
onlab
.
onos
.
openflow
.
controller
.
RoleState
.*;
/**
* Provider which uses an OpenFlow controller to detect network
* infrastructure links.
...
...
@@ -68,9 +82,61 @@ public class OpenFlowPacketProvider extends AbstractProvider implements PacketPr
@Override
public
void
emit
(
OutboundPacket
packet
)
{
DeviceId
devId
=
packet
.
sendThrough
();
String
scheme
=
devId
.
toString
().
split
(
":"
)[
0
];
if
(!
scheme
.
equals
(
this
.
id
().
scheme
()))
{
throw
new
IllegalArgumentException
(
"Don't know how to handle Device with scheme "
+
scheme
);
}
Dpid
dpid
=
Dpid
.
dpid
(
devId
.
uri
());
OpenFlowSwitch
sw
=
controller
.
getSwitch
(
dpid
);
if
(
sw
==
null
)
{
log
.
warn
(
"Device {} isn't available?"
,
devId
);
return
;
}
else
if
(
sw
.
getRole
().
equals
(
SLAVE
))
{
log
.
warn
(
"Can't write to Device {} as slave"
,
devId
);
return
;
}
Ethernet
eth
=
new
Ethernet
();
eth
.
deserialize
(
packet
.
data
().
array
(),
0
,
packet
.
data
().
array
().
length
);
OFPortDesc
p
=
null
;
for
(
Instruction
inst
:
packet
.
treatment
().
instructions
())
{
if
(
inst
.
type
().
equals
(
Instruction
.
Type
.
OUTPUT
))
{
p
=
portDesc
(((
OutputInstruction
)
inst
).
port
());
if
(!
sw
.
getPorts
().
contains
(
p
))
{
log
.
warn
(
"Tried to write out non-existint port {}"
,
p
.
getPortNo
());
continue
;
}
OFPacketOut
po
=
packetOut
(
sw
,
eth
,
p
.
getPortNo
());
sw
.
sendMsg
(
po
);
}
}
}
private
OFPortDesc
portDesc
(
PortNumber
port
)
{
OFPortDesc
.
Builder
builder
=
OFFactoryVer10
.
INSTANCE
.
buildPortDesc
();
builder
.
setPortNo
(
OFPort
.
of
((
int
)
port
.
toLong
()));
return
builder
.
build
();
}
private
OFPacketOut
packetOut
(
OpenFlowSwitch
sw
,
Ethernet
eth
,
OFPort
out
)
{
OFPacketOut
.
Builder
builder
=
sw
.
factory
().
buildPacketOut
();
OFAction
act
=
sw
.
factory
().
actions
()
.
buildOutput
()
.
setPort
(
out
)
.
build
();
return
builder
.
setBufferId
(
OFBufferId
.
NO_BUFFER
)
.
setInPort
(
OFPort
.
NO_MASK
)
.
setActions
(
Collections
.
singletonList
(
act
))
.
setData
(
eth
.
serialize
())
.
build
();
}
/**
* Internal Packet Provider implementation.
...
...
providers/openflow/packet/src/test/java/org/onlab/onos/provider/of/packet/impl/OpenFlowPacketProviderTest.java
0 → 100644
View file @
70b2e48
This diff is collapsed. Click to expand it.
Please
register
or
login
to post a comment