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
Thomas Vachuska
2014-11-06 07:56:38 -0800
Browse Files
Options
Browse Files
Download
Plain Diff
Committed by
Gerrit Code Review
2014-11-06 07:56:38 -0800
Commit
3dc5435e2140c507fa3243f44bf5de44ea2e493c
3dc5435e
2 parents
0c6e1840
0e51fe55
Merge "Add constraint for waypoints"
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
196 additions
and
0 deletions
core/api/pom.xml
core/api/src/main/java/org/onlab/onos/net/intent/constraint/WaypointConstraint.java
core/api/src/test/java/org/onlab/onos/net/intent/constraint/WaypointConstraintTest.java
core/api/pom.xml
View file @
3dc5435
...
...
@@ -40,6 +40,10 @@
<groupId>
joda-time
</groupId>
<artifactId>
joda-time
</artifactId>
</dependency>
<dependency>
<groupId>
org.easymock
</groupId>
<artifactId>
easymock
</artifactId>
</dependency>
</dependencies>
</project>
...
...
core/api/src/main/java/org/onlab/onos/net/intent/constraint/WaypointConstraint.java
0 → 100644
View file @
3dc5435
/*
* Copyright 2014 Open Networking Laboratory
*
* Licensed 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
.
net
.
intent
.
constraint
;
import
com.google.common.base.MoreObjects
;
import
com.google.common.collect.ImmutableList
;
import
org.onlab.onos.net.ElementId
;
import
org.onlab.onos.net.Link
;
import
org.onlab.onos.net.Path
;
import
org.onlab.onos.net.intent.Constraint
;
import
org.onlab.onos.net.resource.LinkResourceService
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Objects
;
import
static
com
.
google
.
common
.
base
.
Preconditions
.
checkArgument
;
import
static
com
.
google
.
common
.
base
.
Preconditions
.
checkNotNull
;
/**
* Constraint that evaluates elements passed through in order.
*/
public
class
WaypointConstraint
implements
Constraint
{
private
final
List
<
ElementId
>
waypoints
;
/**
* Creates a new waypoint constraint.
*
* @param waypoints waypoints
*/
public
WaypointConstraint
(
ElementId
...
waypoints
)
{
checkNotNull
(
waypoints
,
"waypoints cannot be null"
);
checkArgument
(
waypoints
.
length
>
0
,
"length of waypoints should be more than 0"
);
this
.
waypoints
=
ImmutableList
.
copyOf
(
waypoints
);
}
@Override
public
double
cost
(
Link
link
,
LinkResourceService
resourceService
)
{
// Always consider the number of hops
return
1
;
}
@Override
public
boolean
validate
(
Path
path
,
LinkResourceService
resourceService
)
{
LinkedList
<
ElementId
>
waypoints
=
new
LinkedList
<>(
this
.
waypoints
);
ElementId
current
=
waypoints
.
poll
();
// This is safe because Path class ensures the number of links are more than 0
Link
firstLink
=
path
.
links
().
get
(
0
);
if
(
firstLink
.
src
().
elementId
().
equals
(
current
))
{
current
=
waypoints
.
poll
();
}
for
(
Link
link
:
path
.
links
())
{
if
(
link
.
dst
().
elementId
().
equals
(
current
))
{
current
=
waypoints
.
poll
();
// Empty waypoints means passing through all waypoints in the specified order
if
(
current
==
null
)
{
return
true
;
}
}
}
return
false
;
}
@Override
public
int
hashCode
()
{
return
Objects
.
hash
(
waypoints
);
}
@Override
public
boolean
equals
(
Object
obj
)
{
if
(
this
==
obj
)
{
return
true
;
}
if
(!(
obj
instanceof
WaypointConstraint
))
{
return
false
;
}
final
WaypointConstraint
that
=
(
WaypointConstraint
)
obj
;
return
Objects
.
equals
(
this
.
waypoints
,
that
.
waypoints
);
}
@Override
public
String
toString
()
{
return
MoreObjects
.
toStringHelper
(
this
)
.
add
(
"waypoints"
,
waypoints
)
.
toString
();
}
}
core/api/src/test/java/org/onlab/onos/net/intent/constraint/WaypointConstraintTest.java
0 → 100644
View file @
3dc5435
/*
* Copyright 2014 Open Networking Laboratory
*
* Licensed 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
.
net
.
intent
.
constraint
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.onlab.onos.net.DefaultLink
;
import
org.onlab.onos.net.DefaultPath
;
import
org.onlab.onos.net.DeviceId
;
import
org.onlab.onos.net.Path
;
import
org.onlab.onos.net.PortNumber
;
import
org.onlab.onos.net.provider.ProviderId
;
import
org.onlab.onos.net.resource.LinkResourceService
;
import
java.util.Arrays
;
import
static
org
.
easymock
.
EasyMock
.
createMock
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
onlab
.
onos
.
net
.
DefaultLinkTest
.
cp
;
import
static
org
.
onlab
.
onos
.
net
.
DeviceId
.
deviceId
;
import
static
org
.
onlab
.
onos
.
net
.
Link
.
Type
.
DIRECT
;
/**
* Test for constraint of intermediate elements.
*/
public
class
WaypointConstraintTest
{
public
static
final
DeviceId
DID1
=
deviceId
(
"of:1"
);
public
static
final
DeviceId
DID2
=
deviceId
(
"of:2"
);
public
static
final
DeviceId
DID3
=
deviceId
(
"of:3"
);
public
static
final
DeviceId
DID4
=
deviceId
(
"of:4"
);
public
static
final
PortNumber
PN1
=
PortNumber
.
portNumber
(
1
);
public
static
final
PortNumber
PN2
=
PortNumber
.
portNumber
(
2
);
public
static
final
PortNumber
PN3
=
PortNumber
.
portNumber
(
3
);
public
static
final
PortNumber
PN4
=
PortNumber
.
portNumber
(
4
);
public
static
final
ProviderId
PROVIDER_ID
=
new
ProviderId
(
"of"
,
"foo"
);
private
WaypointConstraint
sut
;
private
LinkResourceService
linkResourceService
;
private
Path
path
;
private
DefaultLink
link2
;
private
DefaultLink
link1
;
@Before
public
void
setUp
()
{
linkResourceService
=
createMock
(
LinkResourceService
.
class
);
link1
=
new
DefaultLink
(
PROVIDER_ID
,
cp
(
DID1
,
PN1
),
cp
(
DID2
,
PN2
),
DIRECT
);
link2
=
new
DefaultLink
(
PROVIDER_ID
,
cp
(
DID2
,
PN3
),
cp
(
DID3
,
PN4
),
DIRECT
);
path
=
new
DefaultPath
(
PROVIDER_ID
,
Arrays
.
asList
(
link1
,
link2
),
10
);
}
/**
* Tests that all of the specified waypoints are included in the specified path in order.
*/
@Test
public
void
testSatisfyWaypoints
()
{
sut
=
new
WaypointConstraint
(
DID1
,
DID2
,
DID3
);
assertThat
(
sut
.
validate
(
path
,
linkResourceService
),
is
(
true
));
}
/**
* Tests that the specified path does not includes the specified waypoint.
*/
@Test
public
void
testNotSatisfyWaypoint
()
{
sut
=
new
WaypointConstraint
(
DID4
);
assertThat
(
sut
.
validate
(
path
,
linkResourceService
),
is
(
false
));
}
}
Please
register
or
login
to post a comment