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
Madan Jampani
2014-10-20 15:35:17 -0700
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
a665855401559a9a9d1a1b4d7ed466eb286c9c43
a6658554
2 parents
5e83f333
f2dbde57
Merge branch 'master' of
ssh://gerrit.onlab.us:29418/onos-next
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
82 additions
and
75 deletions
core/api/src/main/java/org/onlab/onos/net/intent/IntentInstaller.java
core/api/src/main/java/org/onlab/onos/net/resource/LinkResourceService.java
core/api/src/test/java/org/onlab/onos/net/intent/IntentServiceTest.java
core/net/src/main/java/org/onlab/onos/net/intent/impl/IntentManager.java
core/net/src/main/java/org/onlab/onos/net/intent/impl/LinkCollectionIntentInstaller.java
core/net/src/main/java/org/onlab/onos/net/intent/impl/PathIntentInstaller.java
core/api/src/main/java/org/onlab/onos/net/intent/IntentInstaller.java
View file @
a665855
package
org
.
onlab
.
onos
.
net
.
intent
;
import
java.util.
concurrent.Future
;
import
java.util.
List
;
import
org.onlab.onos.net.flow.
Completed
BatchOperation
;
import
org.onlab.onos.net.flow.
FlowRule
BatchOperation
;
/**
* Abstraction of entity capable of installing intents to the environment.
...
...
@@ -14,7 +14,7 @@ public interface IntentInstaller<T extends InstallableIntent> {
* @param intent intent to be installed
* @throws IntentException if issues are encountered while installing the intent
*/
Future
<
Completed
BatchOperation
>
install
(
T
intent
);
List
<
FlowRule
BatchOperation
>
install
(
T
intent
);
/**
* Uninstalls the specified intent from the environment.
...
...
@@ -22,5 +22,5 @@ public interface IntentInstaller<T extends InstallableIntent> {
* @param intent intent to be uninstalled
* @throws IntentException if issues are encountered while uninstalling the intent
*/
Future
<
Completed
BatchOperation
>
uninstall
(
T
intent
);
List
<
FlowRule
BatchOperation
>
uninstall
(
T
intent
);
}
...
...
core/api/src/main/java/org/onlab/onos/net/resource/LinkResourceService.java
View file @
a665855
...
...
@@ -56,5 +56,5 @@ public interface LinkResourceService {
* @param link a target link
* @return available resources for the target link
*/
LinkResource
availableResources
(
Link
link
);
LinkResource
s
availableResources
(
Link
link
);
}
...
...
core/api/src/test/java/org/onlab/onos/net/intent/IntentServiceTest.java
View file @
a665855
...
...
@@ -14,12 +14,11 @@ import java.util.Arrays;
import
java.util.Collections
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.concurrent.Future
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.onlab.onos.net.flow.
Completed
BatchOperation
;
import
org.onlab.onos.net.flow.
FlowRule
BatchOperation
;
/**
* Suite of tests for the intent service contract.
...
...
@@ -298,7 +297,7 @@ public class IntentServiceTest {
}
@Override
public
Future
<
Completed
BatchOperation
>
install
(
TestInstallableIntent
intent
)
{
public
List
<
FlowRule
BatchOperation
>
install
(
TestInstallableIntent
intent
)
{
if
(
fail
)
{
throw
new
IntentException
(
"install failed by design"
);
}
...
...
@@ -306,7 +305,7 @@ public class IntentServiceTest {
}
@Override
public
Future
<
Completed
BatchOperation
>
uninstall
(
TestInstallableIntent
intent
)
{
public
List
<
FlowRule
BatchOperation
>
uninstall
(
TestInstallableIntent
intent
)
{
if
(
fail
)
{
throw
new
IntentException
(
"remove failed by design"
);
}
...
...
core/net/src/main/java/org/onlab/onos/net/intent/impl/IntentManager.java
View file @
a665855
...
...
@@ -34,6 +34,8 @@ import org.apache.felix.scr.annotations.Service;
import
org.onlab.onos.event.AbstractListenerRegistry
;
import
org.onlab.onos.event.EventDeliveryService
;
import
org.onlab.onos.net.flow.CompletedBatchOperation
;
import
org.onlab.onos.net.flow.FlowRuleBatchOperation
;
import
org.onlab.onos.net.flow.FlowRuleService
;
import
org.onlab.onos.net.intent.InstallableIntent
;
import
org.onlab.onos.net.intent.Intent
;
import
org.onlab.onos.net.intent.IntentCompiler
;
...
...
@@ -90,6 +92,9 @@ public class IntentManager
@Reference
(
cardinality
=
ReferenceCardinality
.
MANDATORY_UNARY
)
protected
EventDeliveryService
eventDispatcher
;
@Reference
(
cardinality
=
ReferenceCardinality
.
MANDATORY_UNARY
)
protected
FlowRuleService
flowRuleService
;
@Activate
public
void
activate
()
{
store
.
setDelegate
(
delegate
);
...
...
@@ -283,7 +288,7 @@ public class IntentManager
// Indicate that the intent is entering the installing phase.
store
.
setState
(
intent
,
INSTALLING
);
List
<
F
uture
<
CompletedBatchOperation
>>
installFutures
=
Lists
.
newArrayList
();
List
<
F
lowRuleBatchOperation
>
installWork
=
Lists
.
newArrayList
();
try
{
List
<
InstallableIntent
>
installables
=
store
.
getInstallableIntents
(
intent
.
id
());
if
(
installables
!=
null
)
{
...
...
@@ -291,13 +296,13 @@ public class IntentManager
registerSubclassInstallerIfNeeded
(
installable
);
trackerService
.
addTrackedResources
(
intent
.
id
(),
installable
.
requiredLinks
());
Future
<
CompletedBatchOperation
>
future
=
getInstaller
(
installable
).
install
(
installable
);
install
Futures
.
add
(
future
);
List
<
FlowRuleBatchOperation
>
batch
=
getInstaller
(
installable
).
install
(
installable
);
install
Work
.
addAll
(
batch
);
}
}
// FIXME we have to wait for the installable intents
//eventDispatcher.post(store.setState(intent, INSTALLED));
monitorExecutor
.
execute
(
new
IntentInstallMonitor
(
intent
,
install
Futures
,
INSTALLED
));
monitorExecutor
.
execute
(
new
IntentInstallMonitor
(
intent
,
install
Work
,
INSTALLED
));
}
catch
(
Exception
e
)
{
log
.
warn
(
"Unable to install intent {} due to: {}"
,
intent
.
id
(),
e
);
uninstallIntent
(
intent
,
RECOMPILING
);
...
...
@@ -369,16 +374,16 @@ public class IntentManager
* @param intent intent to be uninstalled
*/
private
void
uninstallIntent
(
Intent
intent
,
IntentState
nextState
)
{
List
<
F
uture
<
CompletedBatchOperation
>>
uninstallFutures
=
Lists
.
newArrayList
();
List
<
F
lowRuleBatchOperation
>
uninstallWork
=
Lists
.
newArrayList
();
try
{
List
<
InstallableIntent
>
installables
=
store
.
getInstallableIntents
(
intent
.
id
());
if
(
installables
!=
null
)
{
for
(
InstallableIntent
installable
:
installables
)
{
Future
<
CompletedBatchOperation
>
future
=
getInstaller
(
installable
).
uninstall
(
installable
);
uninstall
Futures
.
add
(
future
);
List
<
FlowRuleBatchOperation
>
batches
=
getInstaller
(
installable
).
uninstall
(
installable
);
uninstall
Work
.
addAll
(
batches
);
}
}
monitorExecutor
.
execute
(
new
IntentInstallMonitor
(
intent
,
uninstall
Futures
,
nextState
));
monitorExecutor
.
execute
(
new
IntentInstallMonitor
(
intent
,
uninstall
Work
,
nextState
));
}
catch
(
IntentException
e
)
{
log
.
warn
(
"Unable to uninstall intent {} due to: {}"
,
intent
.
id
(),
e
);
}
...
...
@@ -495,17 +500,27 @@ public class IntentManager
private
class
IntentInstallMonitor
implements
Runnable
{
private
final
Intent
intent
;
private
final
List
<
FlowRuleBatchOperation
>
work
;
private
final
List
<
Future
<
CompletedBatchOperation
>>
futures
;
private
final
IntentState
nextState
;
public
IntentInstallMonitor
(
Intent
intent
,
List
<
Future
<
CompletedBatchOperation
>>
futures
,
IntentState
nextState
)
{
List
<
FlowRuleBatchOperation
>
work
,
IntentState
nextState
)
{
this
.
intent
=
intent
;
this
.
futures
=
futures
;
this
.
work
=
work
;
// TODO how many Futures can be outstanding? one?
this
.
futures
=
Lists
.
newLinkedList
();
this
.
nextState
=
nextState
;
// TODO need to kick off the first batch sometime, why not now?
futures
.
add
(
applyNextBatch
());
}
private
void
updateIntent
(
Intent
intent
)
{
/**
* Update the intent store with the next status for this intent.
*/
private
void
updateIntent
()
{
if
(
nextState
==
RECOMPILING
)
{
executor
.
execute
(
new
IntentTask
(
nextState
,
intent
));
}
else
if
(
nextState
==
INSTALLED
||
nextState
==
WITHDRAWN
)
{
...
...
@@ -515,22 +530,55 @@ public class IntentManager
}
}
@Override
public
void
run
()
{
/**
* Apply a list of FlowRules.
*
* @param rules rules to apply
*/
private
Future
<
CompletedBatchOperation
>
applyNextBatch
()
{
if
(
work
.
isEmpty
())
{
return
null
;
}
FlowRuleBatchOperation
batch
=
work
.
remove
(
0
);
return
flowRuleService
.
applyBatch
(
batch
);
}
/**
* Iterate through the pending futures, and remove them when they have completed.
*/
private
void
processFutures
()
{
List
<
Future
<
CompletedBatchOperation
>>
newFutures
=
Lists
.
newArrayList
();
for
(
Iterator
<
Future
<
CompletedBatchOperation
>>
i
=
futures
.
iterator
();
i
.
hasNext
();)
{
Future
<
CompletedBatchOperation
>
future
=
i
.
next
();
try
{
// TODO: we may want to get the future here and go back to the future.
CompletedBatchOperation
completed
=
future
.
get
(
100
,
TimeUnit
.
NANOSECONDS
);
// TODO check if future succeeded and if not report fail items
if
(
completed
.
isSuccess
())
{
Future
<
CompletedBatchOperation
>
newFuture
=
applyNextBatch
();
if
(
newFuture
!=
null
)
{
// we'll add this later so that we don't get a ConcurrentModException
newFutures
.
add
(
newFuture
);
}
}
else
{
// TODO check if future succeeded and if not report fail items
log
.
warn
(
"Failed items: {}"
,
completed
.
failedItems
());
// TODO revert....
//uninstallIntent(intent, RECOMPILING);
}
i
.
remove
();
}
catch
(
TimeoutException
|
InterruptedException
|
ExecutionException
te
)
{
log
.
debug
(
"Intallations of intent {} is still pending"
,
intent
);
}
}
futures
.
addAll
(
newFutures
);
}
@Override
public
void
run
()
{
processFutures
();
if
(
futures
.
isEmpty
())
{
updateIntent
(
intent
);
// woohoo! we are done!
updateIntent
();
}
else
{
// resubmit ourselves if we are not done yet
monitorExecutor
.
submit
(
this
);
...
...
core/net/src/main/java/org/onlab/onos/net/intent/impl/LinkCollectionIntentInstaller.java
View file @
a665855
...
...
@@ -4,7 +4,6 @@ import static org.onlab.onos.net.flow.DefaultTrafficTreatment.builder;
import
static
org
.
slf4j
.
LoggerFactory
.
getLogger
;
import
java.util.List
;
import
java.util.concurrent.Future
;
import
org.apache.felix.scr.annotations.Activate
;
import
org.apache.felix.scr.annotations.Component
;
...
...
@@ -16,14 +15,12 @@ import org.onlab.onos.CoreService;
import
org.onlab.onos.net.DeviceId
;
import
org.onlab.onos.net.Link
;
import
org.onlab.onos.net.PortNumber
;
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.FlowRule
;
import
org.onlab.onos.net.flow.FlowRuleBatchEntry
;
import
org.onlab.onos.net.flow.FlowRuleBatchEntry.FlowRuleOperation
;
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.onos.net.intent.IntentExtensionService
;
...
...
@@ -47,9 +44,6 @@ public class LinkCollectionIntentInstaller implements IntentInstaller<LinkCollec
protected
IntentExtensionService
intentManager
;
@Reference
(
cardinality
=
ReferenceCardinality
.
MANDATORY_UNARY
)
protected
FlowRuleService
flowRuleService
;
@Reference
(
cardinality
=
ReferenceCardinality
.
MANDATORY_UNARY
)
protected
CoreService
coreService
;
private
ApplicationId
appId
;
...
...
@@ -65,18 +59,8 @@ public class LinkCollectionIntentInstaller implements IntentInstaller<LinkCollec
intentManager
.
unregisterInstaller
(
PathIntent
.
class
);
}
/**
* Apply a list of FlowRules.
*
* @param rules rules to apply
*/
private
Future
<
CompletedBatchOperation
>
applyBatch
(
List
<
FlowRuleBatchEntry
>
rules
)
{
FlowRuleBatchOperation
batch
=
new
FlowRuleBatchOperation
(
rules
);
return
flowRuleService
.
applyBatch
(
batch
);
}
@Override
public
Future
<
Completed
BatchOperation
>
install
(
LinkCollectionIntent
intent
)
{
public
List
<
FlowRule
BatchOperation
>
install
(
LinkCollectionIntent
intent
)
{
TrafficSelector
.
Builder
builder
=
DefaultTrafficSelector
.
builder
(
intent
.
selector
());
List
<
FlowRuleBatchEntry
>
rules
=
Lists
.
newLinkedList
();
...
...
@@ -92,11 +76,11 @@ public class LinkCollectionIntentInstaller implements IntentInstaller<LinkCollec
intent
.
egressPoint
().
deviceId
(),
intent
.
egressPoint
().
port
()));
return
applyBatch
(
rules
);
return
Lists
.
newArrayList
(
new
FlowRuleBatchOperation
(
rules
)
);
}
@Override
public
Future
<
Completed
BatchOperation
>
uninstall
(
LinkCollectionIntent
intent
)
{
public
List
<
FlowRule
BatchOperation
>
uninstall
(
LinkCollectionIntent
intent
)
{
TrafficSelector
.
Builder
builder
=
DefaultTrafficSelector
.
builder
(
intent
.
selector
());
List
<
FlowRuleBatchEntry
>
rules
=
Lists
.
newLinkedList
();
...
...
@@ -113,7 +97,7 @@ public class LinkCollectionIntentInstaller implements IntentInstaller<LinkCollec
intent
.
egressPoint
().
deviceId
(),
intent
.
egressPoint
().
port
()));
return
applyBatch
(
rules
);
return
Lists
.
newArrayList
(
new
FlowRuleBatchOperation
(
rules
)
);
}
/**
...
...
core/net/src/main/java/org/onlab/onos/net/intent/impl/PathIntentInstaller.java
View file @
a665855
...
...
@@ -5,7 +5,6 @@ import static org.slf4j.LoggerFactory.getLogger;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.concurrent.Future
;
import
org.apache.felix.scr.annotations.Activate
;
import
org.apache.felix.scr.annotations.Component
;
...
...
@@ -16,14 +15,12 @@ import org.onlab.onos.ApplicationId;
import
org.onlab.onos.CoreService
;
import
org.onlab.onos.net.ConnectPoint
;
import
org.onlab.onos.net.Link
;
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.FlowRule
;
import
org.onlab.onos.net.flow.FlowRuleBatchEntry
;
import
org.onlab.onos.net.flow.FlowRuleBatchEntry.FlowRuleOperation
;
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.onos.net.intent.IntentExtensionService
;
...
...
@@ -45,9 +42,6 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> {
protected
IntentExtensionService
intentManager
;
@Reference
(
cardinality
=
ReferenceCardinality
.
MANDATORY_UNARY
)
protected
FlowRuleService
flowRuleService
;
@Reference
(
cardinality
=
ReferenceCardinality
.
MANDATORY_UNARY
)
protected
CoreService
coreService
;
private
ApplicationId
appId
;
...
...
@@ -63,31 +57,14 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> {
intentManager
.
unregisterInstaller
(
PathIntent
.
class
);
}
/**
* Apply a list of FlowRules.
*
* @param rules rules to apply
*/
private
Future
<
CompletedBatchOperation
>
applyBatch
(
List
<
FlowRuleBatchEntry
>
rules
)
{
FlowRuleBatchOperation
batch
=
new
FlowRuleBatchOperation
(
rules
);
Future
<
CompletedBatchOperation
>
future
=
flowRuleService
.
applyBatch
(
batch
);
return
future
;
// try {
// //FIXME don't do this here
// future.get();
// } catch (InterruptedException | ExecutionException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
}
@Override
public
Future
<
Completed
BatchOperation
>
install
(
PathIntent
intent
)
{
public
List
<
FlowRule
BatchOperation
>
install
(
PathIntent
intent
)
{
TrafficSelector
.
Builder
builder
=
DefaultTrafficSelector
.
builder
(
intent
.
selector
());
Iterator
<
Link
>
links
=
intent
.
path
().
links
().
iterator
();
ConnectPoint
prev
=
links
.
next
().
dst
();
List
<
FlowRuleBatchEntry
>
rules
=
Lists
.
newLinkedList
();
// TODO Generate multiple batches
while
(
links
.
hasNext
())
{
builder
.
matchInport
(
prev
.
port
());
Link
link
=
links
.
next
();
...
...
@@ -100,18 +77,17 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> {
rules
.
add
(
new
FlowRuleBatchEntry
(
FlowRuleOperation
.
ADD
,
rule
));
prev
=
link
.
dst
();
}
return
applyBatch
(
rules
);
return
Lists
.
newArrayList
(
new
FlowRuleBatchOperation
(
rules
));
}
@Override
public
Future
<
Completed
BatchOperation
>
uninstall
(
PathIntent
intent
)
{
public
List
<
FlowRule
BatchOperation
>
uninstall
(
PathIntent
intent
)
{
TrafficSelector
.
Builder
builder
=
DefaultTrafficSelector
.
builder
(
intent
.
selector
());
Iterator
<
Link
>
links
=
intent
.
path
().
links
().
iterator
();
ConnectPoint
prev
=
links
.
next
().
dst
();
List
<
FlowRuleBatchEntry
>
rules
=
Lists
.
newLinkedList
();
// TODO Generate multiple batches
while
(
links
.
hasNext
())
{
builder
.
matchInport
(
prev
.
port
());
Link
link
=
links
.
next
();
...
...
@@ -123,7 +99,7 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> {
rules
.
add
(
new
FlowRuleBatchEntry
(
FlowRuleOperation
.
REMOVE
,
rule
));
prev
=
link
.
dst
();
}
return
applyBatch
(
rules
);
return
Lists
.
newArrayList
(
new
FlowRuleBatchOperation
(
rules
)
);
}
// TODO refactor below this line... ----------------------------
...
...
Please
register
or
login
to post a comment