Add gRPC API for multicast service.
Change-Id: I003b982145c788e74c39f525122d58f3204b1c0e
diff --git a/incubator/grpc/features.xml b/incubator/grpc/features.xml
new file mode 100644
index 0000000..7f5d98c
--- /dev/null
+++ b/incubator/grpc/features.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+ ~ Copyright 2016-present 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.
+ -->
+<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}">
+ <feature name="${project.artifactId}" version="${project.version}"
+ description="${project.description}">
+ <feature version="${project.version}">grpc</feature>
+
+ <bundle>mvn:com.google.protobuf/protobuf-java/3.0.0</bundle>
+ <bundle>mvn:${project.groupId}/${project.artifactId}/${project.version}</bundle>
+ </feature>
+
+ <feature name="grpc-netty" version="${project.version}"
+ description="gRPC Netty dependencies">
+ <bundle>mvn:io.netty/netty-common/${grpc.netty.version}</bundle>
+ <bundle>mvn:io.netty/netty-buffer/${grpc.netty.version}</bundle>
+ <bundle>mvn:io.netty/netty-transport/${grpc.netty.version}</bundle>
+ <bundle>mvn:io.netty/netty-handler/${grpc.netty.version}</bundle>
+ <bundle>mvn:io.netty/netty-codec/${grpc.netty.version}</bundle>
+ <bundle>mvn:io.netty/netty-codec-http/${grpc.netty.version}</bundle>
+ <bundle>mvn:io.netty/netty-codec-http2/${grpc.netty.version}</bundle>
+ <bundle>mvn:io.netty/netty-resolver/${grpc.netty.version}</bundle>
+ </feature>
+
+ <feature name="grpc" version="${project.version}" description="gRPC dependencies">
+ <feature version="${project.version}">grpc-netty</feature>
+ <bundle>wrap:mvn:com.google.auth/google-auth-library-credentials/${google.auth.version}$Bundle-SymbolicName=com.google.auth.google-auth-library-credentials&Bundle-Version=${google.auth.version}</bundle>
+ <bundle>wrap:mvn:com.google.auth/google-auth-library-oauth2-http/${google.auth.version}$Bundle-SymbolicName=com.google.auth.google-auth-library-oauth2-http&Bundle-Version=${google.auth.version}</bundle>
+ <!-- Export for io.grpc.internal required for DnsNameResolverProvider -->
+ <bundle>wrap:mvn:io.grpc/grpc-core/${grpc.version}$Bundle-SymbolicName=io.grpc.grpc-core&Bundle-Version=${grpc.package.version}&Export-Package=*;version=${grpc.package.version},io.grpc.internal;version=${grpc.package.version}&</bundle>
+ <bundle>wrap:mvn:io.grpc/grpc-protobuf-lite/${grpc.version}$Bundle-SymbolicName=io.grpc.grpc-protobuf-lite&Bundle-Version=${grpc.package.version}&</bundle>
+ <bundle>wrap:mvn:io.grpc/grpc-protobuf/${grpc.version}$Bundle-SymbolicName=io.grpc.grpc-protobuf&Bundle-Version=${grpc.package.version}&</bundle>
+ <bundle>wrap:mvn:io.grpc/grpc-stub/${grpc.version}$Bundle-SymbolicName=io.grpc.grpc-stub&Bundle-Version=${grpc.package.version}&</bundle>
+ <bundle>wrap:mvn:io.grpc/grpc-netty/${grpc.version}$Bundle-SymbolicName=io.grpc.grpc-netty&Bundle-Version=${grpc.package.version}&Import-Package=io.netty.*;version=${grpc.netty.package.version},*</bundle>
+ <bundle>wrap:mvn:io.grpc/grpc-auth/${grpc.version}$Bundle-SymbolicName=io.grpc.grpc-auth&Bundle-Version=${grpc.package.version}&Import-Package=javax.net.ssl,*</bundle>
+ </feature>
+
+</features>
diff --git a/incubator/grpc/pom.xml b/incubator/grpc/pom.xml
new file mode 100644
index 0000000..7b6fed0
--- /dev/null
+++ b/incubator/grpc/pom.xml
@@ -0,0 +1,132 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2016-present 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.
+ -->
+
+<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/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>onos-incubator</artifactId>
+ <groupId>org.onosproject</groupId>
+ <version>1.7.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>onos-incubator-grpc</artifactId>
+ <packaging>bundle</packaging>
+
+ <properties>
+ <onos.app.name>org.onosproject.incubator.grpc</onos.app.name>
+ <onos.app.title>gRPC dependency package</onos.app.title>
+ <protobuf.version>3.0.0</protobuf.version>
+ <grpc.version>1.0.0-pre2</grpc.version>
+ <grpc.package.version>1.0.0</grpc.package.version>
+ <grpc.netty.version>4.1.3.Final</grpc.netty.version>
+ <grpc.netty.package.version>4.1.3</grpc.netty.package.version>
+ <google.auth.version>0.4.0</google.auth.version>
+ </properties>
+
+ <!-- gRPC requires more recent version of netty -->
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>io.grpc</groupId>
+ <artifactId>grpc-core</artifactId>
+ <version>${grpc.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>io.grpc</groupId>
+ <artifactId>grpc-protobuf</artifactId>
+ <version>${grpc.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>io.grpc</groupId>
+ <artifactId>grpc-stub</artifactId>
+ <version>${grpc.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>io.grpc</groupId>
+ <artifactId>grpc-netty</artifactId>
+ <version>${grpc.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>io.grpc</groupId>
+ <artifactId>grpc-auth</artifactId>
+ <version>${grpc.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>io.netty</groupId>
+ <artifactId>netty-codec</artifactId>
+ <version>${grpc.netty.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>io.netty</groupId>
+ <artifactId>netty-transport</artifactId>
+ <version>${grpc.netty.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>io.netty</groupId>
+ <artifactId>netty-handler</artifactId>
+ <version>${grpc.netty.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>io.netty</groupId>
+ <artifactId>netty-buffer</artifactId>
+ <version>${grpc.netty.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>io.netty</groupId>
+ <artifactId>netty-common</artifactId>
+ <version>${grpc.netty.version}</version>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>io.grpc</groupId>
+ <artifactId>grpc-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.grpc</groupId>
+ <artifactId>grpc-protobuf</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.grpc</groupId>
+ <artifactId>grpc-stub</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.grpc</groupId>
+ <artifactId>grpc-netty</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.grpc</groupId>
+ <artifactId>grpc-auth</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+
+</project>
diff --git a/incubator/pom.xml b/incubator/pom.xml
index a8c7f9d..5dbd8b4 100644
--- a/incubator/pom.xml
+++ b/incubator/pom.xml
@@ -38,6 +38,9 @@
<module>protobuf</module>
<module>rpc</module>
<module>rpc-grpc</module>
+ <module>rpc-nb</module>
+ <module>protobuf-nb</module>
+ <module>grpc</module>
</modules>
<dependencies>
diff --git a/incubator/protobuf-nb/pom.xml b/incubator/protobuf-nb/pom.xml
new file mode 100644
index 0000000..7919a43
--- /dev/null
+++ b/incubator/protobuf-nb/pom.xml
@@ -0,0 +1,132 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2016-present 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.
+ -->
+
+<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/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>onos-incubator</artifactId>
+ <groupId>org.onosproject</groupId>
+ <version>1.7.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>onos-incubator-protobuf-nb</artifactId>
+ <packaging>bundle</packaging>
+
+ <properties>
+ <protobuf.version>3.0.0</protobuf.version>
+ <grpc.version>1.0.0-pre2</grpc.version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>io.grpc</groupId>
+ <artifactId>grpc-core</artifactId>
+ <version>${grpc.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>io.grpc</groupId>
+ <artifactId>grpc-protobuf</artifactId>
+ <version>${grpc.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>io.grpc</groupId>
+ <artifactId>grpc-stub</artifactId>
+ <version>${grpc.version}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <extensions>
+ <extension>
+ <groupId>kr.motd.maven</groupId>
+ <artifactId>os-maven-plugin</artifactId>
+ <version>1.4.1.Final</version>
+ </extension>
+ </extensions>
+
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.karaf.tooling</groupId>
+ <artifactId>karaf-maven-plugin</artifactId>
+ <version>3.0.5</version>
+ <extensions>true</extensions>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+
+ <plugins>
+ <!-- TODO This is included to suppress the generation of javadocs for
+ this package. There is a problem when we try to package the
+ auto-generated code's javadoc into a jar. -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <configuration>
+ <sourcepath>${basedir}/src/main/java/</sourcepath>
+ <excludePackageNames>org.onosproject.grpc.net.mcast</excludePackageNames>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.xolstice.maven.plugins</groupId>
+ <artifactId>protobuf-maven-plugin</artifactId>
+ <version>0.5.0</version>
+ <configuration>
+ <!-- The version of protoc must match protobuf-java. If you don't
+ depend on protobuf-java directly, you will be transitively depending on the
+ protobuf-java version that grpc depends on. -->
+ <protocArtifact>com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier}</protocArtifact>
+ <pluginId>grpc-java</pluginId>
+ <pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}</pluginArtifact>
+ </configuration>
+ <executions>
+ <execution>
+ <goals>
+ <goal>compile</goal>
+ <goal>compile-custom</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <version>1.11</version>
+ <executions>
+ <execution>
+ <id>add-source</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>add-source</goal>
+ </goals>
+ <configuration>
+ <sources>
+ <source>${project.build.directory}/generated-sources/protobuf/java</source>
+ <source>${project.build.directory}/generated-sources/protobuf/grpc-java</source>
+ </sources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/incubator/protobuf-nb/src/main/proto/MulticastRouteService.proto b/incubator/protobuf-nb/src/main/proto/MulticastRouteService.proto
new file mode 100644
index 0000000..f74048a
--- /dev/null
+++ b/incubator/protobuf-nb/src/main/proto/MulticastRouteService.proto
@@ -0,0 +1,51 @@
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.mcast";
+
+package Multicast;
+
+// TODO move model objects to common protobuf package
+
+message ConnectPoint {
+ string deviceId = 1;
+ uint64 portNumber = 2;
+}
+
+enum MulticastRouteType {
+ PIM = 0;
+ IGMP = 1;
+ STATIC = 2;
+}
+
+enum MulticastOperationResult {
+ SUCCESS = 0;
+ FAIL = 1;
+}
+
+enum MulticastOperation {
+ ADD_ROUTE = 0;
+ ADD_SOURCE = 1;
+ ADD_SINK = 2;
+ REMOVE_ROUTE = 3;
+ REMOVE_SOURCE = 4;
+ REMOVE_SINK = 5;
+}
+
+message MulticastRoute {
+ fixed32 source = 1; // TODO assumes ipv4
+ fixed32 group = 2;
+ MulticastRouteType type = 3;
+}
+
+message MulticastReply {
+ MulticastOperationResult result = 1;
+}
+
+message MulticastRequest {
+ MulticastOperation operation = 1;
+ MulticastRoute route = 2;
+ ConnectPoint connectPoint = 3;
+}
+
+service MulticastRouteService {
+ rpc operation(stream MulticastRequest) returns (stream MulticastReply) {}
+}
diff --git a/incubator/rpc-nb/features.xml b/incubator/rpc-nb/features.xml
new file mode 100644
index 0000000..e9d7073
--- /dev/null
+++ b/incubator/rpc-nb/features.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+ ~ Copyright 2015-present 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.
+ -->
+<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}">
+ <feature name="${project.artifactId}" version="${project.version}"
+ description="${project.description}">
+ <feature>onos-api</feature>
+ <feature>onos-incubator-grpc</feature>
+
+ <bundle>mvn:${project.groupId}/onos-incubator-protobuf-nb/${project.version}</bundle>
+ <bundle>mvn:${project.groupId}/${project.artifactId}/${project.version}</bundle>
+ </feature>
+</features>
diff --git a/incubator/rpc-nb/pom.xml b/incubator/rpc-nb/pom.xml
new file mode 100644
index 0000000..e60a47f
--- /dev/null
+++ b/incubator/rpc-nb/pom.xml
@@ -0,0 +1,122 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2016-present 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.
+ -->
+
+<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/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>onos-incubator</artifactId>
+ <groupId>org.onosproject</groupId>
+ <version>1.7.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>onos-incubator-rpc-nb</artifactId>
+ <packaging>bundle</packaging>
+
+ <description>ONOS northbound RPC based on gRPC</description>
+ <url>http://onosproject.org</url>
+
+ <properties>
+ <onos.app.name>org.onosproject.incubator.rpc-nb</onos.app.name>
+ <onos.app.title>ONOS gRPC Northbound API</onos.app.title>
+ <onos.app.requires>org.onosproject.incubator.grpc</onos.app.requires>
+ <grpc.version>1.0.0-pre2</grpc.version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-api</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-incubator-api</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onlab-osgi</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>io.grpc</groupId>
+ <artifactId>grpc-core</artifactId>
+ <version>${grpc.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>io.grpc</groupId>
+ <artifactId>grpc-protobuf</artifactId>
+ <version>${grpc.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>io.grpc</groupId>
+ <artifactId>grpc-stub</artifactId>
+ <version>${grpc.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>io.grpc</groupId>
+ <artifactId>grpc-netty</artifactId>
+ <version>${grpc.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>io.grpc</groupId>
+ <artifactId>grpc-auth</artifactId>
+ <version>${grpc.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-incubator-protobuf-nb</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.scr.annotations</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>generate-scr-srcdescriptor</id>
+ <goals>
+ <goal>scr</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <!-- avoid searching into wrong source path -->
+ <scanClasses>true</scanClasses>
+ <supportedProjectTypes>
+ <supportedProjectType>bundle</supportedProjectType>
+ <supportedProjectType>war</supportedProjectType>
+ </supportedProjectTypes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/incubator/rpc-nb/src/main/java/org/onosproject/incubator/rpc/nb/impl/GrpcServer.java b/incubator/rpc-nb/src/main/java/org/onosproject/incubator/rpc/nb/impl/GrpcServer.java
new file mode 100644
index 0000000..abd4c4a
--- /dev/null
+++ b/incubator/rpc-nb/src/main/java/org/onosproject/incubator/rpc/nb/impl/GrpcServer.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2016-present 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.onosproject.incubator.rpc.nb.impl;
+
+import io.grpc.Server;
+import io.grpc.netty.NettyServerBuilder;
+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.onosproject.incubator.rpc.nb.mcast.MulticastRouteGrpcService;
+import org.onosproject.net.mcast.MulticastRouteService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+
+/**
+ * gRPC server for northbound APIs.
+ */
+@Component(immediate = true)
+public class GrpcServer {
+
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected MulticastRouteService multicastRouteService;
+
+ // TODO make configurable
+ private int port = 50051;
+
+ private Server server;
+
+ @Activate
+ public void activate() {
+ start();
+ log.info("Started");
+ }
+
+ @Deactivate
+ public void deactivate() {
+ stop();
+ log.info("Stopped");
+ }
+
+ private void start() {
+ try {
+ server = NettyServerBuilder.forPort(port)
+ .addService(new MulticastRouteGrpcService(multicastRouteService))
+ .build()
+ .start();
+ log.info("gRPC server started listening on " + port);
+ } catch (IOException e) {
+ log.error("Failed to start gRPC server", e);
+ }
+ }
+
+ private void stop() {
+ if (server != null) {
+ server.shutdown();
+ }
+ }
+}
diff --git a/incubator/rpc-nb/src/main/java/org/onosproject/incubator/rpc/nb/impl/package-info.java b/incubator/rpc-nb/src/main/java/org/onosproject/incubator/rpc/nb/impl/package-info.java
new file mode 100644
index 0000000..4aadc11
--- /dev/null
+++ b/incubator/rpc-nb/src/main/java/org/onosproject/incubator/rpc/nb/impl/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2016-present 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.
+ */
+
+/**
+ * Northbound gPRC implementation.
+ */
+package org.onosproject.incubator.rpc.nb.impl;
diff --git a/incubator/rpc-nb/src/main/java/org/onosproject/incubator/rpc/nb/mcast/MulticastRouteGrpcService.java b/incubator/rpc-nb/src/main/java/org/onosproject/incubator/rpc/nb/mcast/MulticastRouteGrpcService.java
new file mode 100644
index 0000000..c6347f5
--- /dev/null
+++ b/incubator/rpc-nb/src/main/java/org/onosproject/incubator/rpc/nb/mcast/MulticastRouteGrpcService.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2016-present 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.onosproject.incubator.rpc.nb.mcast;
+
+import io.grpc.stub.StreamObserver;
+import org.onlab.packet.IpAddress;
+import org.onosproject.grpc.net.mcast.MulticastRouteServiceGrpc;
+import org.onosproject.grpc.net.mcast.MulticastRouteServiceOuterClass;
+import org.onosproject.net.mcast.McastRoute;
+import org.onosproject.net.mcast.MulticastRouteService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.annotations.Beta;
+
+/**
+ * Implementation of multicast gRPC service.
+ */
+@Beta
+public class MulticastRouteGrpcService
+ extends MulticastRouteServiceGrpc.MulticastRouteServiceImplBase {
+
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ private final MulticastRouteService multicastRouteService;
+
+ public MulticastRouteGrpcService(MulticastRouteService service) {
+ this.multicastRouteService = service;
+ }
+
+ @Override
+ public StreamObserver<MulticastRouteServiceOuterClass.MulticastRequest>
+ operation(StreamObserver<MulticastRouteServiceOuterClass.MulticastReply> responseObserver) {
+
+ return new MulticastServiceServerProxy(responseObserver);
+ }
+
+ private final class MulticastServiceServerProxy
+ implements StreamObserver<MulticastRouteServiceOuterClass.MulticastRequest> {
+
+ private final StreamObserver<MulticastRouteServiceOuterClass.MulticastReply> responseObserver;
+
+ public MulticastServiceServerProxy(
+ StreamObserver<MulticastRouteServiceOuterClass.MulticastReply> responseObserver) {
+ this.responseObserver = responseObserver;
+ }
+
+ @Override
+ public void onNext(MulticastRouteServiceOuterClass.MulticastRequest value) {
+ MulticastRouteServiceOuterClass.MulticastRoute route = value.getRoute();
+
+ switch (value.getOperation()) {
+ case ADD_ROUTE:
+ multicastRouteService.add(
+ new McastRoute(IpAddress.valueOf(route.getSource()),
+ IpAddress.valueOf(route.getGroup()),
+ McastRoute.Type.STATIC));
+ break;
+ case ADD_SOURCE:
+ break;
+ case ADD_SINK:
+ break;
+ case REMOVE_ROUTE:
+ break;
+ case REMOVE_SOURCE:
+ break;
+ case REMOVE_SINK:
+ break;
+ case UNRECOGNIZED:
+ default:
+ break;
+ }
+
+ responseObserver.onNext(MulticastRouteServiceOuterClass.MulticastReply.newBuilder().build());
+ }
+
+ @Override
+ public void onError(Throwable t) {
+ log.warn("Error receiving multicast route", t);
+ }
+
+ @Override
+ public void onCompleted() {
+ // When the client closes their stream, we'll close ours too
+ responseObserver.onCompleted();
+ }
+ }
+}
diff --git a/incubator/rpc-nb/src/main/java/org/onosproject/incubator/rpc/nb/mcast/package-info.java b/incubator/rpc-nb/src/main/java/org/onosproject/incubator/rpc/nb/mcast/package-info.java
new file mode 100644
index 0000000..9b42471
--- /dev/null
+++ b/incubator/rpc-nb/src/main/java/org/onosproject/incubator/rpc/nb/mcast/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2016-present 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.
+ */
+
+/**
+ * Multicast gRPC implementation.
+ */
+package org.onosproject.incubator.rpc.nb.mcast;