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-10-30 16:28:40 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
5afcbd7317d30b99eefb43a45d152c59d7f0358e
5afcbd73
1 parent
eb5a0b9d
added add-flows command
Change-Id: I240da77d78eebd54eeaa5a0864244920278429a2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
107 additions
and
0 deletions
cli/src/main/java/org/onlab/onos/cli/net/AddFlowsCommand.java
cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
cli/src/main/java/org/onlab/onos/cli/net/AddFlowsCommand.java
0 → 100644
View file @
5afcbd7
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package
org
.
onlab
.
onos
.
cli
.
net
;
import
com.google.common.collect.Sets
;
import
org.apache.karaf.shell.commands.Argument
;
import
org.apache.karaf.shell.commands.Command
;
import
org.onlab.onos.cli.AbstractShellCommand
;
import
org.onlab.onos.net.Device
;
import
org.onlab.onos.net.PortNumber
;
import
org.onlab.onos.net.device.DeviceService
;
import
org.onlab.onos.net.flow.CompletedBatchOperation
;
import
org.onlab.onos.net.flow.DefaultFlowRule
;
import
org.onlab.onos.net.flow.DefaultTrafficSelector
;
import
org.onlab.onos.net.flow.DefaultTrafficTreatment
;
import
org.onlab.onos.net.flow.FlowRuleBatchEntry
;
import
org.onlab.onos.net.flow.FlowRuleBatchOperation
;
import
org.onlab.onos.net.flow.FlowRuleService
;
import
org.onlab.onos.net.flow.TrafficSelector
;
import
org.onlab.onos.net.flow.TrafficTreatment
;
import
org.onlab.packet.MacAddress
;
import
java.util.Set
;
import
java.util.concurrent.ExecutionException
;
import
java.util.concurrent.Future
;
/**
* Installs many many flows.
*/
@Command
(
scope
=
"onos"
,
name
=
"add-flows"
,
description
=
"Installs a flow rules"
)
public
class
AddFlowsCommand
extends
AbstractShellCommand
{
@Argument
(
index
=
0
,
name
=
"flowPerDevice"
,
description
=
"Number of flows to add per device"
,
required
=
true
,
multiValued
=
false
)
String
flows
=
null
;
@Override
protected
void
execute
()
{
FlowRuleService
flowService
=
get
(
FlowRuleService
.
class
);
DeviceService
deviceService
=
get
(
DeviceService
.
class
);
int
flowsPerDevice
=
Integer
.
parseInt
(
flows
);
Iterable
<
Device
>
devices
=
deviceService
.
getDevices
();
TrafficTreatment
treatment
=
DefaultTrafficTreatment
.
builder
()
.
setOutput
(
PortNumber
.
portNumber
(
1
)).
build
();
TrafficSelector
.
Builder
sbuilder
;
Set
<
FlowRuleBatchEntry
>
rules
=
Sets
.
newHashSet
();
Set
<
FlowRuleBatchEntry
>
remove
=
Sets
.
newHashSet
();
for
(
Device
d
:
devices
)
{
for
(
int
i
=
0
;
i
<
flowsPerDevice
;
i
++)
{
sbuilder
=
DefaultTrafficSelector
.
builder
();
sbuilder
.
matchEthSrc
(
MacAddress
.
valueOf
(
i
))
.
matchEthDst
(
MacAddress
.
valueOf
(
Integer
.
MAX_VALUE
-
i
));
rules
.
add
(
new
FlowRuleBatchEntry
(
FlowRuleBatchEntry
.
FlowRuleOperation
.
ADD
,
new
DefaultFlowRule
(
d
.
id
(),
sbuilder
.
build
(),
treatment
,
100
,
(
long
)
0
,
10
,
false
)));
remove
.
add
(
new
FlowRuleBatchEntry
(
FlowRuleBatchEntry
.
FlowRuleOperation
.
REMOVE
,
new
DefaultFlowRule
(
d
.
id
(),
sbuilder
.
build
(),
treatment
,
100
,
(
long
)
0
,
10
,
false
)));
}
}
long
startTime
=
System
.
currentTimeMillis
();
Future
<
CompletedBatchOperation
>
op
=
flowService
.
applyBatch
(
new
FlowRuleBatchOperation
(
rules
));
CompletedBatchOperation
completed
=
null
;
try
{
completed
=
op
.
get
();
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
catch
(
ExecutionException
e
)
{
e
.
printStackTrace
();
}
long
endTime
=
System
.
currentTimeMillis
();
print
(
"%s AFTER ELAPSED TIME %s"
,
completed
.
isSuccess
()
?
"SUCCESS"
:
"FAILURE"
,
endTime
-
startTime
);
flowService
.
applyBatch
(
new
FlowRuleBatchOperation
(
remove
));
}
}
cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
View file @
5afcbd7
...
...
@@ -183,6 +183,10 @@
</command>
<command>
<action
class=
"org.onlab.onos.cli.net.AddFlowsCommand"
/>
</command>
<command>
<action
class=
"org.onlab.onos.cli.net.WipeOutCommand"
/>
</command>
</command-bundle>
...
...
Please
register
or
login
to post a comment