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-08-28 16:11:28 -0700
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
132b58a6a8f6db64012596a898bf7df0a27b8c28
132b58a6
1 parent
4f3b18b6
Added some tests.
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
132 additions
and
7 deletions
net/api/src/main/java/org/onlab/onos/net/provider/AbstractProviderRegistry.java
net/api/src/main/java/org/onlab/onos/net/provider/ProviderRegistry.java
net/api/src/test/java/org/onlab/onos/net/provider/AbstractProviderRegistryTest.java
net/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/DeviceStore.java
net/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleDeviceManager.java
net/api/src/main/java/org/onlab/onos/net/provider/AbstractProviderRegistry.java
View file @
132b58a
package
org
.
onlab
.
onos
.
net
.
provider
;
import
com.google.common.collect.ImmutableSet
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Set
;
import
static
com
.
google
.
common
.
base
.
Preconditions
.
checkArgument
;
import
static
com
.
google
.
common
.
base
.
Preconditions
.
checkNotNull
;
import
static
com
.
google
.
common
.
base
.
Preconditions
.
checkState
;
/**
* Base implementation of provider registry.
...
...
@@ -28,7 +31,7 @@ public abstract class AbstractProviderRegistry<P extends Provider, S extends Pro
@Override
public
synchronized
S
register
(
P
provider
)
{
checkNotNull
(
provider
,
"Provider cannot be null"
);
check
Argument
(!
services
.
containsKey
(
provider
),
"Provider %s already registered"
,
provider
.
id
());
check
State
(!
services
.
containsKey
(
provider
.
id
()
),
"Provider %s already registered"
,
provider
.
id
());
S
service
=
createProviderService
(
provider
);
services
.
put
(
provider
.
id
(),
service
);
return
service
;
...
...
@@ -37,10 +40,16 @@ public abstract class AbstractProviderRegistry<P extends Provider, S extends Pro
@Override
public
synchronized
void
unregister
(
P
provider
)
{
checkNotNull
(
provider
,
"Provider cannot be null"
);
S
service
=
services
.
get
(
provider
);
S
service
=
services
.
get
(
provider
.
id
()
);
if
(
service
!=
null
&&
service
instanceof
AbstractProviderService
)
{
((
AbstractProviderService
)
service
).
invalidate
();
services
.
remove
(
provider
);
services
.
remove
(
provider
.
id
()
);
}
}
@Override
public
synchronized
Set
<
ProviderId
>
getProviders
()
{
return
ImmutableSet
.
copyOf
(
services
.
keySet
());
}
}
...
...
net/api/src/main/java/org/onlab/onos/net/provider/ProviderRegistry.java
View file @
132b58a
package
org
.
onlab
.
onos
.
net
.
provider
;
import
java.util.Set
;
/**
* Registry for tracking information providers with the core.
*
...
...
@@ -29,4 +31,11 @@ public interface ProviderRegistry<P extends Provider, S extends ProviderService<
*/
void
unregister
(
P
provider
);
/**
* Returns a set of currently registered provider identities.
*
* @return set of provider identifiers
*/
Set
<
ProviderId
>
getProviders
();
}
...
...
net/api/src/test/java/org/onlab/onos/net/provider/AbstractProviderRegistryTest.java
0 → 100644
View file @
132b58a
package
org
.
onlab
.
onos
.
net
.
provider
;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
MatcherAssert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
/**
* Test of the base provider registry.
*/
public
class
AbstractProviderRegistryTest
{
private
class
TestProviderService
extends
AbstractProviderService
<
TestProvider
>
{
protected
TestProviderService
(
TestProvider
provider
)
{
super
(
provider
);
}
}
private
class
TestProviderRegistry
extends
AbstractProviderRegistry
<
TestProvider
,
TestProviderService
>
{
@Override
protected
TestProviderService
createProviderService
(
TestProvider
provider
)
{
return
new
TestProviderService
(
provider
);
}
}
@Test
public
void
basics
()
{
TestProviderRegistry
registry
=
new
TestProviderRegistry
();
assertEquals
(
"incorrect provider count"
,
0
,
registry
.
getProviders
().
size
());
ProviderId
fooId
=
new
ProviderId
(
"foo"
);
TestProvider
pFoo
=
new
TestProvider
(
fooId
);
TestProviderService
psFoo
=
registry
.
register
(
pFoo
);
assertEquals
(
"incorrect provider count"
,
1
,
registry
.
getProviders
().
size
());
assertThat
(
"provider not found"
,
registry
.
getProviders
().
contains
(
fooId
));
assertEquals
(
"incorrect provider"
,
psFoo
.
provider
(),
pFoo
);
ProviderId
barId
=
new
ProviderId
(
"bar"
);
TestProvider
pBar
=
new
TestProvider
(
barId
);
TestProviderService
psBar
=
registry
.
register
(
pBar
);
assertEquals
(
"incorrect provider count"
,
2
,
registry
.
getProviders
().
size
());
assertThat
(
"provider not found"
,
registry
.
getProviders
().
contains
(
barId
));
assertEquals
(
"incorrect provider"
,
psBar
.
provider
(),
pBar
);
psFoo
.
checkValidity
();
registry
.
unregister
(
pFoo
);
psBar
.
checkValidity
();
assertEquals
(
"incorrect provider count"
,
1
,
registry
.
getProviders
().
size
());
assertThat
(
"provider not found"
,
registry
.
getProviders
().
contains
(
barId
));
}
@Test
(
expected
=
IllegalStateException
.
class
)
public
void
duplicateRegistration
()
{
TestProviderRegistry
registry
=
new
TestProviderRegistry
();
TestProvider
pFoo
=
new
TestProvider
(
new
ProviderId
(
"foo"
));
registry
.
register
(
pFoo
);
registry
.
register
(
pFoo
);
}
@Test
public
void
voidUnregistration
()
{
TestProviderRegistry
registry
=
new
TestProviderRegistry
();
registry
.
unregister
(
new
TestProvider
(
new
ProviderId
(
"foo"
)));
}
@Test
(
expected
=
IllegalStateException
.
class
)
public
void
unregistration
()
{
TestProviderRegistry
registry
=
new
TestProviderRegistry
();
TestProvider
pFoo
=
new
TestProvider
(
new
ProviderId
(
"foo"
));
TestProviderService
psFoo
=
registry
.
register
(
pFoo
);
registry
.
unregister
(
pFoo
);
psFoo
.
checkValidity
();
}
}
net/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/DeviceStore.java
View file @
132b58a
...
...
@@ -2,6 +2,8 @@ package org.onlab.onos.net.trivial.impl;
import
org.onlab.onos.net.Device
;
import
org.onlab.onos.net.DeviceId
;
import
org.onlab.onos.net.Port
;
import
org.onlab.onos.net.PortNumber
;
import
org.onlab.onos.net.device.DeviceDescription
;
import
org.onlab.onos.net.device.DeviceEvent
;
import
org.onlab.onos.net.device.PortDescription
;
...
...
@@ -66,4 +68,35 @@ public class DeviceStore {
PortDescription
portDescription
)
{
return
null
;
}
/**
* Returns the device with the specified identifier.
*
* @param deviceId device identifier
* @return device
*/
public
Device
getDevice
(
DeviceId
deviceId
)
{
return
null
;
}
/**
* Returns the list of ports that belong to the specified device.
*
* @param deviceId device identifier
* @return list of device ports
*/
public
List
<
Port
>
getPorts
(
DeviceId
deviceId
)
{
return
null
;
}
/**
* Returns the specified device port.
*
* @param deviceId device identifier
* @param portNumber port number
* @return device port
*/
public
Port
getPort
(
DeviceId
deviceId
,
PortNumber
portNumber
)
{
return
null
;
}
}
...
...
net/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleDeviceManager.java
View file @
132b58a
...
...
@@ -80,20 +80,20 @@ public class SimpleDeviceManager
@Override
public
Device
getDevice
(
DeviceId
deviceId
)
{
checkNotNull
(
deviceId
,
DEVICE_ID_NULL
);
return
null
;
return
store
.
getDevice
(
deviceId
)
;
}
@Override
public
List
<
Port
>
getPorts
(
DeviceId
deviceId
)
{
checkNotNull
(
deviceId
,
DEVICE_ID_NULL
);
return
null
;
return
store
.
getPorts
(
deviceId
)
;
}
@Override
public
Port
getPort
(
DeviceId
deviceId
,
PortNumber
portNumber
)
{
checkNotNull
(
deviceId
,
DEVICE_ID_NULL
);
checkNotNull
(
portNumber
,
PORT_NUMBER_NULL
);
return
null
;
return
store
.
getPort
(
deviceId
,
portNumber
)
;
}
@Override
...
...
Please
register
or
login
to post a comment