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
Jonathan Hart
2014-09-29 20:03:50 -0700
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
74f9c3b0431726184163bc5c30b1106e7aa2020b
74f9c3b0
1 parent
cccd6b95
Added config app to read address config from json file
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
271 additions
and
0 deletions
apps/config/pom.xml
apps/config/src/main/java/org/onlab/onos/config/AddressConfiguration.java
apps/config/src/main/java/org/onlab/onos/config/AddressEntry.java
apps/config/src/main/java/org/onlab/onos/config/NetworkConfigReader.java
apps/config/src/main/java/org/onlab/onos/config/package-info.java
apps/config/src/main/resources/config.json
apps/pom.xml
core/api/src/main/java/org/onlab/onos/net/host/PortAddresses.java
features/features.xml
pom.xml
apps/config/pom.xml
0 → 100644
View file @
74f9c3b
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<parent>
<groupId>
org.onlab.onos
</groupId>
<artifactId>
onos-apps
</artifactId>
<version>
1.0.0-SNAPSHOT
</version>
<relativePath>
../pom.xml
</relativePath>
</parent>
<artifactId>
onos-app-config
</artifactId>
<packaging>
bundle
</packaging>
<description>
ONOS simple network configuration reader
</description>
<dependencies>
<dependency>
<groupId>
org.codehaus.jackson
</groupId>
<artifactId>
jackson-core-asl
</artifactId>
</dependency>
<dependency>
<groupId>
org.codehaus.jackson
</groupId>
<artifactId>
jackson-mapper-asl
</artifactId>
</dependency>
<dependency>
<groupId>
com.fasterxml.jackson.core
</groupId>
<artifactId>
jackson-annotations
</artifactId>
<version>
2.4.2
</version>
<scope>
provided
</scope>
</dependency>
</dependencies>
</project>
apps/config/src/main/java/org/onlab/onos/config/AddressConfiguration.java
0 → 100644
View file @
74f9c3b
package
org
.
onlab
.
onos
.
config
;
import
java.util.Collections
;
import
java.util.List
;
import
org.codehaus.jackson.annotate.JsonProperty
;
/**
* Object to store address configuration read from a JSON file.
*/
public
class
AddressConfiguration
{
private
List
<
AddressEntry
>
addresses
;
/**
* Gets a list of addresses in the system.
*
* @return the list of addresses
*/
public
List
<
AddressEntry
>
getAddresses
()
{
return
Collections
.
unmodifiableList
(
addresses
);
}
/**
* Sets a list of addresses in the system.
*
* @param addresses the list of addresses
*/
@JsonProperty
(
"addresses"
)
public
void
setAddresses
(
List
<
AddressEntry
>
addresses
)
{
this
.
addresses
=
addresses
;
}
}
apps/config/src/main/java/org/onlab/onos/config/AddressEntry.java
0 → 100644
View file @
74f9c3b
package
org
.
onlab
.
onos
.
config
;
import
java.util.List
;
import
org.codehaus.jackson.annotate.JsonProperty
;
import
org.onlab.packet.IpPrefix
;
import
org.onlab.packet.MacAddress
;
/**
* Represents a set of addresses bound to a port.
*/
public
class
AddressEntry
{
private
String
dpid
;
private
short
portNumber
;
private
List
<
IpPrefix
>
ipAddresses
;
private
MacAddress
macAddress
;
public
String
getDpid
()
{
return
dpid
;
}
@JsonProperty
(
"dpid"
)
public
void
setDpid
(
String
strDpid
)
{
this
.
dpid
=
strDpid
;
}
public
short
getPortNumber
()
{
return
portNumber
;
}
@JsonProperty
(
"port"
)
public
void
setPortNumber
(
short
portNumber
)
{
this
.
portNumber
=
portNumber
;
}
public
List
<
IpPrefix
>
getIpAddresses
()
{
return
ipAddresses
;
}
@JsonProperty
(
"ips"
)
public
void
setIpAddresses
(
List
<
IpPrefix
>
ipAddresses
)
{
this
.
ipAddresses
=
ipAddresses
;
}
public
MacAddress
getMacAddress
()
{
return
macAddress
;
}
@JsonProperty
(
"mac"
)
public
void
setMacAddress
(
MacAddress
macAddress
)
{
this
.
macAddress
=
macAddress
;
}
}
apps/config/src/main/java/org/onlab/onos/config/NetworkConfigReader.java
0 → 100644
View file @
74f9c3b
package
org
.
onlab
.
onos
.
config
;
import
static
org
.
slf4j
.
LoggerFactory
.
getLogger
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
org.apache.felix.scr.annotations.Activate
;
import
org.apache.felix.scr.annotations.Component
;
import
org.apache.felix.scr.annotations.Deactivate
;
import
org.apache.felix.scr.annotations.Reference
;
import
org.apache.felix.scr.annotations.ReferenceCardinality
;
import
org.codehaus.jackson.map.ObjectMapper
;
import
org.onlab.onos.net.ConnectPoint
;
import
org.onlab.onos.net.DeviceId
;
import
org.onlab.onos.net.PortNumber
;
import
org.onlab.onos.net.host.HostAdminService
;
import
org.onlab.onos.net.host.PortAddresses
;
import
org.slf4j.Logger
;
import
com.google.common.collect.Sets
;
/**
* Simple configuration module to read in supplementary network configuration
* from a file.
*/
@Component
(
immediate
=
true
)
public
class
NetworkConfigReader
{
private
final
Logger
log
=
getLogger
(
getClass
());
private
static
final
String
DEFAULT_CONFIG_FILE
=
"config/addresses.json"
;
private
String
configFileName
=
DEFAULT_CONFIG_FILE
;
@Reference
(
cardinality
=
ReferenceCardinality
.
MANDATORY_UNARY
)
protected
HostAdminService
hostAdminService
;
@Activate
protected
void
activate
()
{
log
.
info
(
"Started network config reader"
);
log
.
info
(
"Config file set to {}"
,
configFileName
);
AddressConfiguration
config
=
readNetworkConfig
();
if
(
config
!=
null
)
{
for
(
AddressEntry
entry
:
config
.
getAddresses
())
{
ConnectPoint
cp
=
new
ConnectPoint
(
DeviceId
.
deviceId
(
dpidToUri
(
entry
.
getDpid
())),
PortNumber
.
portNumber
(
entry
.
getPortNumber
()));
PortAddresses
addresses
=
new
PortAddresses
(
cp
,
Sets
.
newHashSet
(
entry
.
getIpAddresses
()),
entry
.
getMacAddress
());
hostAdminService
.
bindAddressesToPort
(
addresses
);
}
}
}
@Deactivate
protected
void
deactivate
()
{
log
.
info
(
"Stopped"
);
}
private
AddressConfiguration
readNetworkConfig
()
{
File
configFile
=
new
File
(
configFileName
);
ObjectMapper
mapper
=
new
ObjectMapper
();
try
{
AddressConfiguration
config
=
mapper
.
readValue
(
configFile
,
AddressConfiguration
.
class
);
return
config
;
}
catch
(
FileNotFoundException
e
)
{
log
.
warn
(
"Configuration file not found: {}"
,
configFileName
);
}
catch
(
IOException
e
)
{
log
.
error
(
"Unable to read config from file:"
,
e
);
}
return
null
;
}
private
static
String
dpidToUri
(
String
dpid
)
{
return
"of:"
+
dpid
.
replace
(
":"
,
""
);
}
}
apps/config/src/main/java/org/onlab/onos/config/package-info.java
0 → 100644
View file @
74f9c3b
/**
* Simple configuration module to read in supplementary network configuration
* from a file.
*/
package
org
.
onlab
.
onos
.
config
;
apps/config/src/main/resources/config.json
0 → 100644
View file @
74f9c3b
{
"interfaces"
:
[
{
"dpid"
:
"00:00:00:00:00:00:01"
,
"port"
:
"1"
,
"ips"
:
[
"192.168.10.101/24"
],
"mac"
:
"00:00:00:11:22:33"
},
{
"dpid"
:
"00:00:00:00:00:00:02"
,
"port"
:
"1"
,
"ips"
:
[
"192.168.20.101/24"
,
"192.168.30.101/24"
]
},
{
"dpid"
:
"00:00:00:00:00:00:03"
,
"port"
:
"1"
,
"ips"
:
[
"10.1.0.1/16"
],
"mac"
:
"00:00:00:00:00:01"
}
]
}
apps/pom.xml
View file @
74f9c3b
...
...
@@ -20,6 +20,7 @@
<module>
tvue
</module>
<module>
fwd
</module>
<module>
foo
</module>
<module>
config
</module>
</modules>
<properties>
...
...
core/api/src/main/java/org/onlab/onos/net/host/PortAddresses.java
View file @
74f9c3b
...
...
@@ -9,6 +9,8 @@ import org.onlab.onos.net.ConnectPoint;
import
org.onlab.packet.IpPrefix
;
import
org.onlab.packet.MacAddress
;
import
com.google.common.base.MoreObjects
;
/**
* Represents address information bound to a port.
*/
...
...
@@ -83,4 +85,13 @@ public class PortAddresses {
public
int
hashCode
()
{
return
Objects
.
hash
(
connectPoint
,
ipAddresses
,
macAddress
);
}
@Override
public
String
toString
()
{
return
MoreObjects
.
toStringHelper
(
getClass
())
.
add
(
"connect-point"
,
connectPoint
)
.
add
(
"ip-addresses"
,
ipAddresses
)
.
add
(
"mac-address"
,
macAddress
)
.
toString
();
}
}
...
...
features/features.xml
View file @
74f9c3b
...
...
@@ -19,6 +19,9 @@
<bundle>
mvn:de.javakaffee/kryo-serializers/0.27
</bundle>
<bundle>
mvn:org.onlab.onos/onlab-nio/1.0.0-SNAPSHOT
</bundle>
<bundle>
mvn:org.codehaus.jackson/jackson-core-asl/1.9.13
</bundle>
<bundle>
mvn:org.codehaus.jackson/jackson-mapper-asl/1.9.13
</bundle>
</feature>
<feature
name=
"onos-thirdparty-web"
version=
"1.0.0"
...
...
@@ -122,4 +125,10 @@
<bundle>
mvn:org.onlab.onos/onos-app-foo/1.0.0-SNAPSHOT
</bundle>
</feature>
<feature
name=
"onos-app-config"
version=
"1.0.0"
description=
"ONOS network config reader"
>
<feature>
onos-api
</feature>
<bundle>
mvn:org.onlab.onos/onos-app-config/1.0.0-SNAPSHOT
</bundle>
</feature>
</features>
...
...
pom.xml
View file @
74f9c3b
...
...
@@ -92,6 +92,17 @@
<version>
3.3.2
</version>
</dependency>
<dependency>
<groupId>
org.codehaus.jackson
</groupId>
<artifactId>
jackson-core-asl
</artifactId>
<version>
1.9.13
</version>
</dependency>
<dependency>
<groupId>
org.codehaus.jackson
</groupId>
<artifactId>
jackson-mapper-asl
</artifactId>
<version>
1.9.13
</version>
</dependency>
<!-- Web related -->
<dependency>
...
...
Please
register
or
login
to post a comment