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-09-03 21:56:43 -0700
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
3065d12993d6c87aed8b9137bfc674e9c5aefe9c
3065d129
1 parent
6f5460bb
Adding mode base model and unit tests stuff.
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
247 additions
and
0 deletions
net/api/src/main/java/org/onlab/onos/net/AbstractElement.java
net/api/src/main/java/org/onlab/onos/net/AbstractModel.java
net/api/src/main/java/org/onlab/onos/net/DefaultDevice.java
net/api/src/test/java/org/onlab/onos/net/DefaultDeviceTest.java
net/api/src/test/java/org/onlab/onos/net/device/DefaultDeviceDescriptionTest.java
net/api/src/main/java/org/onlab/onos/net/AbstractElement.java
0 → 100644
View file @
3065d12
package
org
.
onlab
.
onos
.
net
;
import
org.onlab.onos.net.provider.ProviderId
;
/**
* Base implementation of network elements, i.e. devices or hosts.
*/
public
class
AbstractElement
extends
AbstractModel
implements
Element
{
protected
final
ElementId
id
;
/**
* Creates a network element attributed to the specified provider.
*
* @param providerId identity of the provider
* @param id element identifier
*/
protected
AbstractElement
(
ProviderId
providerId
,
ElementId
id
)
{
super
(
providerId
);
this
.
id
=
id
;
}
@Override
public
ElementId
id
()
{
return
id
;
}
}
net/api/src/main/java/org/onlab/onos/net/AbstractModel.java
0 → 100644
View file @
3065d12
package
org
.
onlab
.
onos
.
net
;
import
org.onlab.onos.net.provider.ProviderId
;
/**
* Base implementation of a network model entity.
*/
public
class
AbstractModel
implements
Provided
{
private
final
ProviderId
providerId
;
/**
* Creates a model entity attributed to the specified provider.
*
* @param providerId identity of the provider
*/
protected
AbstractModel
(
ProviderId
providerId
)
{
this
.
providerId
=
providerId
;
}
@Override
public
ProviderId
providerId
()
{
return
providerId
;
}
}
net/api/src/main/java/org/onlab/onos/net/DefaultDevice.java
0 → 100644
View file @
3065d12
package
org
.
onlab
.
onos
.
net
;
import
org.onlab.onos.net.provider.ProviderId
;
import
java.util.Objects
;
import
static
com
.
google
.
common
.
base
.
Objects
.
toStringHelper
;
/**
* Default device model implementation.
*/
public
class
DefaultDevice
extends
AbstractElement
implements
Device
{
private
final
Type
type
;
private
final
String
manufacturer
;
private
final
String
serialNumber
;
private
final
String
hwVersion
;
private
final
String
swVersion
;
/**
* Creates a network element attributed to the specified provider.
*
* @param providerId identity of the provider
* @param id device identifier
* @param type device type
* @param manufacturer device manufacturer
* @param hwVersion device HW version
* @param swVersion device SW version
* @param serialNumber device serial number
*/
public
DefaultDevice
(
ProviderId
providerId
,
DeviceId
id
,
Type
type
,
String
manufacturer
,
String
hwVersion
,
String
swVersion
,
String
serialNumber
)
{
super
(
providerId
,
id
);
this
.
type
=
type
;
this
.
manufacturer
=
manufacturer
;
this
.
hwVersion
=
hwVersion
;
this
.
swVersion
=
swVersion
;
this
.
serialNumber
=
serialNumber
;
}
@Override
public
DeviceId
id
()
{
return
(
DeviceId
)
super
.
id
();
}
@Override
public
Type
type
()
{
return
type
;
}
@Override
public
String
manufacturer
()
{
return
manufacturer
;
}
@Override
public
String
hwVersion
()
{
return
hwVersion
;
}
@Override
public
String
swVersion
()
{
return
swVersion
;
}
@Override
public
String
serialNumber
()
{
return
serialNumber
;
}
@Override
public
int
hashCode
()
{
return
Objects
.
hash
(
id
,
type
,
manufacturer
,
hwVersion
,
swVersion
,
serialNumber
);
}
@Override
public
boolean
equals
(
Object
obj
)
{
if
(
obj
instanceof
DefaultDevice
)
{
final
DefaultDevice
other
=
(
DefaultDevice
)
obj
;
return
Objects
.
equals
(
this
.
id
,
other
.
id
)
&&
Objects
.
equals
(
this
.
type
,
other
.
type
)
&&
Objects
.
equals
(
this
.
manufacturer
,
other
.
manufacturer
)
&&
Objects
.
equals
(
this
.
hwVersion
,
other
.
hwVersion
)
&&
Objects
.
equals
(
this
.
swVersion
,
other
.
swVersion
)
&&
Objects
.
equals
(
this
.
serialNumber
,
other
.
serialNumber
);
}
return
false
;
}
@Override
public
String
toString
()
{
return
toStringHelper
(
this
)
.
add
(
"id"
,
id
)
.
add
(
"type"
,
type
)
.
add
(
"manufacturer"
,
manufacturer
)
.
add
(
"hwVersion"
,
hwVersion
)
.
add
(
"swVersion"
,
swVersion
)
.
add
(
"serialNumber"
,
serialNumber
)
.
toString
();
}
}
net/api/src/test/java/org/onlab/onos/net/DefaultDeviceTest.java
0 → 100644
View file @
3065d12
package
org
.
onlab
.
onos
.
net
;
import
com.google.common.testing.EqualsTester
;
import
org.junit.Test
;
import
org.onlab.onos.net.provider.ProviderId
;
import
java.net.URI
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
onlab
.
onos
.
net
.
Device
.
Type
.
SWITCH
;
/**
* Test of the default device model entity.
*/
public
class
DefaultDeviceTest
{
private
static
final
ProviderId
PID
=
new
ProviderId
(
"foo"
);
private
static
final
DeviceId
DID1
=
new
DeviceId
(
URI
.
create
(
"of:foo"
));
private
static
final
DeviceId
DID2
=
new
DeviceId
(
URI
.
create
(
"of:bar"
));
private
static
final
String
MFR
=
"whitebox"
;
private
static
final
String
HW
=
"1.1.x"
;
private
static
final
String
SW
=
"3.9.1"
;
private
static
final
String
SN1
=
"43311-12345"
;
private
static
final
String
SN2
=
"42346-43512"
;
@Test
public
void
testEquality
()
{
Device
d1
=
new
DefaultDevice
(
PID
,
DID1
,
SWITCH
,
MFR
,
HW
,
SW
,
SN1
);
Device
d2
=
new
DefaultDevice
(
PID
,
DID1
,
SWITCH
,
MFR
,
HW
,
SW
,
SN1
);
Device
d3
=
new
DefaultDevice
(
PID
,
DID2
,
SWITCH
,
MFR
,
HW
,
SW
,
SN2
);
Device
d4
=
new
DefaultDevice
(
PID
,
DID2
,
SWITCH
,
MFR
,
HW
,
SW
,
SN2
);
Device
d5
=
new
DefaultDevice
(
PID
,
DID2
,
SWITCH
,
MFR
,
HW
,
SW
,
SN1
);
new
EqualsTester
().
addEqualityGroup
(
d1
,
d2
)
.
addEqualityGroup
(
d3
,
d4
)
.
addEqualityGroup
(
d5
)
.
testEquals
();
}
@Test
public
void
basics
()
{
Device
device
=
new
DefaultDevice
(
PID
,
DID1
,
SWITCH
,
MFR
,
HW
,
SW
,
SN1
);
assertEquals
(
"incorrect provider"
,
PID
,
device
.
providerId
());
assertEquals
(
"incorrect id"
,
DID1
,
device
.
id
());
assertEquals
(
"incorrect type"
,
SWITCH
,
device
.
type
());
assertEquals
(
"incorrect manufacturer"
,
MFR
,
device
.
manufacturer
());
assertEquals
(
"incorrect hw"
,
HW
,
device
.
hwVersion
());
assertEquals
(
"incorrect sw"
,
SW
,
device
.
swVersion
());
assertEquals
(
"incorrect serial"
,
SN1
,
device
.
serialNumber
());
assertEquals
(
"incorrect serial"
,
SN1
,
device
.
serialNumber
());
}
}
net/api/src/test/java/org/onlab/onos/net/device/DefaultDeviceDescriptionTest.java
0 → 100644
View file @
3065d12
package
org
.
onlab
.
onos
.
net
.
device
;
import
org.junit.Test
;
import
java.net.URI
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
onlab
.
onos
.
net
.
Device
.
Type
.
SWITCH
;
/**
* Test of the default device description.
*/
public
class
DefaultDeviceDescriptionTest
{
private
static
final
URI
DURI
=
URI
.
create
(
"of:foo"
);
private
static
final
String
MFR
=
"whitebox"
;
private
static
final
String
HW
=
"1.1.x"
;
private
static
final
String
SW
=
"3.9.1"
;
private
static
final
String
SN
=
"43311-12345"
;
@Test
public
void
basics
()
{
DeviceDescription
device
=
new
DefaultDeviceDescription
(
DURI
,
SWITCH
,
MFR
,
HW
,
SW
,
SN
);
assertEquals
(
"incorrect uri"
,
DURI
,
device
.
deviceURI
());
assertEquals
(
"incorrect type"
,
SWITCH
,
device
.
type
());
assertEquals
(
"incorrect manufacturer"
,
MFR
,
device
.
manufacturer
());
assertEquals
(
"incorrect hw"
,
HW
,
device
.
hwVersion
());
assertEquals
(
"incorrect sw"
,
SW
,
device
.
swVersion
());
assertEquals
(
"incorrect serial"
,
SN
,
device
.
serialNumber
());
assertTrue
(
"incorrect toString"
,
device
.
toString
().
contains
(
"uri=of:foo"
));
}
}
Please
register
or
login
to post a comment