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 17:26:49 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
3460da1ca9cfd6a504b3ce25da212aa1820a1b0c
3460da1c
1 parent
1c81a0e5
polished add-flow command
Change-Id: I67b957d18820b2447ebddf09f4aa95ab67e6c0b8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
33 deletions
cli/src/main/java/org/onlab/onos/cli/net/AddFlowsCommand.java
cli/src/main/java/org/onlab/onos/cli/net/AddFlowsCommand.java
View file @
3460da1
/*
* 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.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.node.ArrayNode
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Sets
;
import
org.apache.karaf.shell.commands.Argument
;
import
org.apache.karaf.shell.commands.Command
;
...
...
@@ -36,6 +23,7 @@ import org.onlab.onos.net.flow.TrafficSelector;
import
org.onlab.onos.net.flow.TrafficTreatment
;
import
org.onlab.packet.MacAddress
;
import
java.util.ArrayList
;
import
java.util.Set
;
import
java.util.concurrent.ExecutionException
;
import
java.util.concurrent.Future
;
...
...
@@ -51,6 +39,9 @@ public class AddFlowsCommand extends AbstractShellCommand {
required
=
true
,
multiValued
=
false
)
String
flows
=
null
;
@Argument
(
index
=
1
,
name
=
"numOfRuns"
,
description
=
"Number of iterations"
,
required
=
true
,
multiValued
=
false
)
String
numOfRuns
=
null
;
@Override
protected
void
execute
()
{
...
...
@@ -59,7 +50,9 @@ public class AddFlowsCommand extends AbstractShellCommand {
DeviceService
deviceService
=
get
(
DeviceService
.
class
);
int
flowsPerDevice
=
Integer
.
parseInt
(
flows
);
int
num
=
Integer
.
parseInt
(
numOfRuns
);
ArrayList
<
Long
>
results
=
Lists
.
newArrayList
();
Iterable
<
Device
>
devices
=
deviceService
.
getDevices
();
TrafficTreatment
treatment
=
DefaultTrafficTreatment
.
builder
()
.
setOutput
(
PortNumber
.
portNumber
(
1
)).
build
();
...
...
@@ -80,24 +73,49 @@ public class AddFlowsCommand extends AbstractShellCommand {
}
}
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
();
boolean
isSuccess
=
true
;
for
(
int
i
=
0
;
i
<
num
;
i
++)
{
long
startTime
=
System
.
currentTimeMillis
();
Future
<
CompletedBatchOperation
>
op
=
flowService
.
applyBatch
(
new
FlowRuleBatchOperation
(
rules
));
try
{
isSuccess
&=
op
.
get
().
isSuccess
();
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
catch
(
ExecutionException
e
)
{
e
.
printStackTrace
();
}
long
endTime
=
System
.
currentTimeMillis
();
results
.
add
(
endTime
-
startTime
);
flowService
.
applyBatch
(
new
FlowRuleBatchOperation
(
remove
));
}
long
endTime
=
System
.
currentTimeMillis
();
print
(
"%s AFTER ELAPSED TIME %s"
,
completed
.
isSuccess
()
?
"SUCCESS"
:
"FAILURE"
,
endTime
-
startTime
);
if
(
outputJson
())
{
print
(
"%s"
,
json
(
new
ObjectMapper
(),
isSuccess
,
results
));
}
else
{
printTime
(
isSuccess
,
results
);
}
flowService
.
applyBatch
(
new
FlowRuleBatchOperation
(
remove
));
}
private
Object
json
(
ObjectMapper
mapper
,
boolean
isSuccess
,
ArrayList
<
Long
>
elapsed
)
{
ObjectNode
result
=
mapper
.
createObjectNode
();
result
.
put
(
"Success"
,
isSuccess
);
ArrayNode
node
=
result
.
putArray
(
"elapsed-time"
);
for
(
Long
v
:
elapsed
)
{
node
.
add
(
v
);
}
return
result
;
}
private
void
printTime
(
boolean
isSuccess
,
ArrayList
<
Long
>
elapsed
)
{
print
(
"Run is %s."
,
isSuccess
?
"success"
:
"failure"
);
for
(
int
i
=
0
;
i
<
elapsed
.
size
();
i
++)
{
print
(
" Run %s : %s"
,
i
,
elapsed
.
get
(
i
));
}
}
}
...
...
Please
register
or
login
to post a comment