Jonathan Hart
Committed by Gerrit Code Review

Add gRPC API for multicast service.

Change-Id: I003b982145c788e74c39f525122d58f3204b1c0e
1 +<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2 +<!--
3 + ~ Copyright 2016-present Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}">
18 + <feature name="${project.artifactId}" version="${project.version}"
19 + description="${project.description}">
20 + <feature version="${project.version}">grpc</feature>
21 +
22 + <bundle>mvn:com.google.protobuf/protobuf-java/3.0.0</bundle>
23 + <bundle>mvn:${project.groupId}/${project.artifactId}/${project.version}</bundle>
24 + </feature>
25 +
26 + <feature name="grpc-netty" version="${project.version}"
27 + description="gRPC Netty dependencies">
28 + <bundle>mvn:io.netty/netty-common/${grpc.netty.version}</bundle>
29 + <bundle>mvn:io.netty/netty-buffer/${grpc.netty.version}</bundle>
30 + <bundle>mvn:io.netty/netty-transport/${grpc.netty.version}</bundle>
31 + <bundle>mvn:io.netty/netty-handler/${grpc.netty.version}</bundle>
32 + <bundle>mvn:io.netty/netty-codec/${grpc.netty.version}</bundle>
33 + <bundle>mvn:io.netty/netty-codec-http/${grpc.netty.version}</bundle>
34 + <bundle>mvn:io.netty/netty-codec-http2/${grpc.netty.version}</bundle>
35 + <bundle>mvn:io.netty/netty-resolver/${grpc.netty.version}</bundle>
36 + </feature>
37 +
38 + <feature name="grpc" version="${project.version}" description="gRPC dependencies">
39 + <feature version="${project.version}">grpc-netty</feature>
40 + <bundle>wrap:mvn:com.google.auth/google-auth-library-credentials/${google.auth.version}$Bundle-SymbolicName=com.google.auth.google-auth-library-credentials&amp;Bundle-Version=${google.auth.version}</bundle>
41 + <bundle>wrap:mvn:com.google.auth/google-auth-library-oauth2-http/${google.auth.version}$Bundle-SymbolicName=com.google.auth.google-auth-library-oauth2-http&amp;Bundle-Version=${google.auth.version}</bundle>
42 + <!-- Export for io.grpc.internal required for DnsNameResolverProvider -->
43 + <bundle>wrap:mvn:io.grpc/grpc-core/${grpc.version}$Bundle-SymbolicName=io.grpc.grpc-core&amp;Bundle-Version=${grpc.package.version}&amp;Export-Package=*;version=${grpc.package.version},io.grpc.internal;version=${grpc.package.version}&amp;</bundle>
44 + <bundle>wrap:mvn:io.grpc/grpc-protobuf-lite/${grpc.version}$Bundle-SymbolicName=io.grpc.grpc-protobuf-lite&amp;Bundle-Version=${grpc.package.version}&amp;</bundle>
45 + <bundle>wrap:mvn:io.grpc/grpc-protobuf/${grpc.version}$Bundle-SymbolicName=io.grpc.grpc-protobuf&amp;Bundle-Version=${grpc.package.version}&amp;</bundle>
46 + <bundle>wrap:mvn:io.grpc/grpc-stub/${grpc.version}$Bundle-SymbolicName=io.grpc.grpc-stub&amp;Bundle-Version=${grpc.package.version}&amp;</bundle>
47 + <bundle>wrap:mvn:io.grpc/grpc-netty/${grpc.version}$Bundle-SymbolicName=io.grpc.grpc-netty&amp;Bundle-Version=${grpc.package.version}&amp;Import-Package=io.netty.*;version=${grpc.netty.package.version},*</bundle>
48 + <bundle>wrap:mvn:io.grpc/grpc-auth/${grpc.version}$Bundle-SymbolicName=io.grpc.grpc-auth&amp;Bundle-Version=${grpc.package.version}&amp;Import-Package=javax.net.ssl,*</bundle>
49 + </feature>
50 +
51 +</features>
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2016-present Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +
18 +<project xmlns="http://maven.apache.org/POM/4.0.0"
19 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21 + <parent>
22 + <artifactId>onos-incubator</artifactId>
23 + <groupId>org.onosproject</groupId>
24 + <version>1.7.0-SNAPSHOT</version>
25 + </parent>
26 + <modelVersion>4.0.0</modelVersion>
27 +
28 + <artifactId>onos-incubator-grpc</artifactId>
29 + <packaging>bundle</packaging>
30 +
31 + <properties>
32 + <onos.app.name>org.onosproject.incubator.grpc</onos.app.name>
33 + <onos.app.title>gRPC dependency package</onos.app.title>
34 + <protobuf.version>3.0.0</protobuf.version>
35 + <grpc.version>1.0.0-pre2</grpc.version>
36 + <grpc.package.version>1.0.0</grpc.package.version>
37 + <grpc.netty.version>4.1.3.Final</grpc.netty.version>
38 + <grpc.netty.package.version>4.1.3</grpc.netty.package.version>
39 + <google.auth.version>0.4.0</google.auth.version>
40 + </properties>
41 +
42 + <!-- gRPC requires more recent version of netty -->
43 + <dependencyManagement>
44 + <dependencies>
45 + <dependency>
46 + <groupId>io.grpc</groupId>
47 + <artifactId>grpc-core</artifactId>
48 + <version>${grpc.version}</version>
49 + </dependency>
50 + <dependency>
51 + <groupId>io.grpc</groupId>
52 + <artifactId>grpc-protobuf</artifactId>
53 + <version>${grpc.version}</version>
54 + </dependency>
55 + <dependency>
56 + <groupId>io.grpc</groupId>
57 + <artifactId>grpc-stub</artifactId>
58 + <version>${grpc.version}</version>
59 + </dependency>
60 + <dependency>
61 + <groupId>io.grpc</groupId>
62 + <artifactId>grpc-netty</artifactId>
63 + <version>${grpc.version}</version>
64 + </dependency>
65 + <dependency>
66 + <groupId>io.grpc</groupId>
67 + <artifactId>grpc-auth</artifactId>
68 + <version>${grpc.version}</version>
69 + </dependency>
70 +
71 + <dependency>
72 + <groupId>io.netty</groupId>
73 + <artifactId>netty-codec</artifactId>
74 + <version>${grpc.netty.version}</version>
75 + </dependency>
76 + <dependency>
77 + <groupId>io.netty</groupId>
78 + <artifactId>netty-transport</artifactId>
79 + <version>${grpc.netty.version}</version>
80 + </dependency>
81 + <dependency>
82 + <groupId>io.netty</groupId>
83 + <artifactId>netty-handler</artifactId>
84 + <version>${grpc.netty.version}</version>
85 + </dependency>
86 + <dependency>
87 + <groupId>io.netty</groupId>
88 + <artifactId>netty-buffer</artifactId>
89 + <version>${grpc.netty.version}</version>
90 + </dependency>
91 + <dependency>
92 + <groupId>io.netty</groupId>
93 + <artifactId>netty-common</artifactId>
94 + <version>${grpc.netty.version}</version>
95 + </dependency>
96 + </dependencies>
97 + </dependencyManagement>
98 +
99 + <dependencies>
100 + <dependency>
101 + <groupId>io.grpc</groupId>
102 + <artifactId>grpc-core</artifactId>
103 + </dependency>
104 + <dependency>
105 + <groupId>io.grpc</groupId>
106 + <artifactId>grpc-protobuf</artifactId>
107 + </dependency>
108 + <dependency>
109 + <groupId>io.grpc</groupId>
110 + <artifactId>grpc-stub</artifactId>
111 + </dependency>
112 + <dependency>
113 + <groupId>io.grpc</groupId>
114 + <artifactId>grpc-netty</artifactId>
115 + </dependency>
116 + <dependency>
117 + <groupId>io.grpc</groupId>
118 + <artifactId>grpc-auth</artifactId>
119 + </dependency>
120 + </dependencies>
121 +
122 + <build>
123 + <plugins>
124 + <plugin>
125 + <groupId>org.onosproject</groupId>
126 + <artifactId>onos-maven-plugin</artifactId>
127 + </plugin>
128 + </plugins>
129 + </build>
130 +
131 +
132 +</project>
...@@ -38,6 +38,9 @@ ...@@ -38,6 +38,9 @@
38 <module>protobuf</module> 38 <module>protobuf</module>
39 <module>rpc</module> 39 <module>rpc</module>
40 <module>rpc-grpc</module> 40 <module>rpc-grpc</module>
41 + <module>rpc-nb</module>
42 + <module>protobuf-nb</module>
43 + <module>grpc</module>
41 </modules> 44 </modules>
42 45
43 <dependencies> 46 <dependencies>
......
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2016-present Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +
18 +<project xmlns="http://maven.apache.org/POM/4.0.0"
19 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21 + <parent>
22 + <artifactId>onos-incubator</artifactId>
23 + <groupId>org.onosproject</groupId>
24 + <version>1.7.0-SNAPSHOT</version>
25 + </parent>
26 + <modelVersion>4.0.0</modelVersion>
27 +
28 + <artifactId>onos-incubator-protobuf-nb</artifactId>
29 + <packaging>bundle</packaging>
30 +
31 + <properties>
32 + <protobuf.version>3.0.0</protobuf.version>
33 + <grpc.version>1.0.0-pre2</grpc.version>
34 + </properties>
35 +
36 + <dependencies>
37 + <dependency>
38 + <groupId>io.grpc</groupId>
39 + <artifactId>grpc-core</artifactId>
40 + <version>${grpc.version}</version>
41 + </dependency>
42 + <dependency>
43 + <groupId>io.grpc</groupId>
44 + <artifactId>grpc-protobuf</artifactId>
45 + <version>${grpc.version}</version>
46 + </dependency>
47 + <dependency>
48 + <groupId>io.grpc</groupId>
49 + <artifactId>grpc-stub</artifactId>
50 + <version>${grpc.version}</version>
51 + </dependency>
52 + </dependencies>
53 +
54 + <build>
55 + <extensions>
56 + <extension>
57 + <groupId>kr.motd.maven</groupId>
58 + <artifactId>os-maven-plugin</artifactId>
59 + <version>1.4.1.Final</version>
60 + </extension>
61 + </extensions>
62 +
63 + <pluginManagement>
64 + <plugins>
65 + <plugin>
66 + <groupId>org.apache.karaf.tooling</groupId>
67 + <artifactId>karaf-maven-plugin</artifactId>
68 + <version>3.0.5</version>
69 + <extensions>true</extensions>
70 + </plugin>
71 + </plugins>
72 + </pluginManagement>
73 +
74 + <plugins>
75 + <!-- TODO This is included to suppress the generation of javadocs for
76 + this package. There is a problem when we try to package the
77 + auto-generated code's javadoc into a jar. -->
78 + <plugin>
79 + <groupId>org.apache.maven.plugins</groupId>
80 + <artifactId>maven-javadoc-plugin</artifactId>
81 + <configuration>
82 + <sourcepath>${basedir}/src/main/java/</sourcepath>
83 + <excludePackageNames>org.onosproject.grpc.net.mcast</excludePackageNames>
84 + </configuration>
85 + </plugin>
86 +
87 + <plugin>
88 + <groupId>org.xolstice.maven.plugins</groupId>
89 + <artifactId>protobuf-maven-plugin</artifactId>
90 + <version>0.5.0</version>
91 + <configuration>
92 + <!-- The version of protoc must match protobuf-java. If you don't
93 + depend on protobuf-java directly, you will be transitively depending on the
94 + protobuf-java version that grpc depends on. -->
95 + <protocArtifact>com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier}</protocArtifact>
96 + <pluginId>grpc-java</pluginId>
97 + <pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}</pluginArtifact>
98 + </configuration>
99 + <executions>
100 + <execution>
101 + <goals>
102 + <goal>compile</goal>
103 + <goal>compile-custom</goal>
104 + </goals>
105 + </execution>
106 + </executions>
107 + </plugin>
108 +
109 + <plugin>
110 + <groupId>org.codehaus.mojo</groupId>
111 + <artifactId>build-helper-maven-plugin</artifactId>
112 + <version>1.11</version>
113 + <executions>
114 + <execution>
115 + <id>add-source</id>
116 + <phase>generate-sources</phase>
117 + <goals>
118 + <goal>add-source</goal>
119 + </goals>
120 + <configuration>
121 + <sources>
122 + <source>${project.build.directory}/generated-sources/protobuf/java</source>
123 + <source>${project.build.directory}/generated-sources/protobuf/grpc-java</source>
124 + </sources>
125 + </configuration>
126 + </execution>
127 + </executions>
128 + </plugin>
129 + </plugins>
130 + </build>
131 +
132 +</project>
1 +syntax = "proto3";
2 +option java_package = "org.onosproject.grpc.net.mcast";
3 +
4 +package Multicast;
5 +
6 +// TODO move model objects to common protobuf package
7 +
8 +message ConnectPoint {
9 + string deviceId = 1;
10 + uint64 portNumber = 2;
11 +}
12 +
13 +enum MulticastRouteType {
14 + PIM = 0;
15 + IGMP = 1;
16 + STATIC = 2;
17 +}
18 +
19 +enum MulticastOperationResult {
20 + SUCCESS = 0;
21 + FAIL = 1;
22 +}
23 +
24 +enum MulticastOperation {
25 + ADD_ROUTE = 0;
26 + ADD_SOURCE = 1;
27 + ADD_SINK = 2;
28 + REMOVE_ROUTE = 3;
29 + REMOVE_SOURCE = 4;
30 + REMOVE_SINK = 5;
31 +}
32 +
33 +message MulticastRoute {
34 + fixed32 source = 1; // TODO assumes ipv4
35 + fixed32 group = 2;
36 + MulticastRouteType type = 3;
37 +}
38 +
39 +message MulticastReply {
40 + MulticastOperationResult result = 1;
41 +}
42 +
43 +message MulticastRequest {
44 + MulticastOperation operation = 1;
45 + MulticastRoute route = 2;
46 + ConnectPoint connectPoint = 3;
47 +}
48 +
49 +service MulticastRouteService {
50 + rpc operation(stream MulticastRequest) returns (stream MulticastReply) {}
51 +}
1 +<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2 +<!--
3 + ~ Copyright 2015-present Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}">
18 + <feature name="${project.artifactId}" version="${project.version}"
19 + description="${project.description}">
20 + <feature>onos-api</feature>
21 + <feature>onos-incubator-grpc</feature>
22 +
23 + <bundle>mvn:${project.groupId}/onos-incubator-protobuf-nb/${project.version}</bundle>
24 + <bundle>mvn:${project.groupId}/${project.artifactId}/${project.version}</bundle>
25 + </feature>
26 +</features>
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2016-present Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +
18 +<project xmlns="http://maven.apache.org/POM/4.0.0"
19 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21 + <parent>
22 + <artifactId>onos-incubator</artifactId>
23 + <groupId>org.onosproject</groupId>
24 + <version>1.7.0-SNAPSHOT</version>
25 + </parent>
26 + <modelVersion>4.0.0</modelVersion>
27 +
28 + <artifactId>onos-incubator-rpc-nb</artifactId>
29 + <packaging>bundle</packaging>
30 +
31 + <description>ONOS northbound RPC based on gRPC</description>
32 + <url>http://onosproject.org</url>
33 +
34 + <properties>
35 + <onos.app.name>org.onosproject.incubator.rpc-nb</onos.app.name>
36 + <onos.app.title>ONOS gRPC Northbound API</onos.app.title>
37 + <onos.app.requires>org.onosproject.incubator.grpc</onos.app.requires>
38 + <grpc.version>1.0.0-pre2</grpc.version>
39 + </properties>
40 +
41 + <dependencies>
42 + <dependency>
43 + <groupId>org.onosproject</groupId>
44 + <artifactId>onos-api</artifactId>
45 + </dependency>
46 +
47 + <dependency>
48 + <groupId>org.onosproject</groupId>
49 + <artifactId>onos-incubator-api</artifactId>
50 + </dependency>
51 +
52 + <dependency>
53 + <groupId>org.onosproject</groupId>
54 + <artifactId>onlab-osgi</artifactId>
55 + </dependency>
56 +
57 + <dependency>
58 + <groupId>io.grpc</groupId>
59 + <artifactId>grpc-core</artifactId>
60 + <version>${grpc.version}</version>
61 + </dependency>
62 + <dependency>
63 + <groupId>io.grpc</groupId>
64 + <artifactId>grpc-protobuf</artifactId>
65 + <version>${grpc.version}</version>
66 + </dependency>
67 + <dependency>
68 + <groupId>io.grpc</groupId>
69 + <artifactId>grpc-stub</artifactId>
70 + <version>${grpc.version}</version>
71 + </dependency>
72 + <dependency>
73 + <groupId>io.grpc</groupId>
74 + <artifactId>grpc-netty</artifactId>
75 + <version>${grpc.version}</version>
76 + </dependency>
77 + <dependency>
78 + <groupId>io.grpc</groupId>
79 + <artifactId>grpc-auth</artifactId>
80 + <version>${grpc.version}</version>
81 + </dependency>
82 +
83 + <dependency>
84 + <groupId>org.onosproject</groupId>
85 + <artifactId>onos-incubator-protobuf-nb</artifactId>
86 + <version>${project.version}</version>
87 + </dependency>
88 +
89 + <dependency>
90 + <groupId>org.apache.felix</groupId>
91 + <artifactId>org.apache.felix.scr.annotations</artifactId>
92 + <scope>provided</scope>
93 + </dependency>
94 +
95 + </dependencies>
96 +
97 + <build>
98 + <plugins>
99 + <plugin>
100 + <groupId>org.apache.felix</groupId>
101 + <artifactId>maven-scr-plugin</artifactId>
102 + <executions>
103 + <execution>
104 + <id>generate-scr-srcdescriptor</id>
105 + <goals>
106 + <goal>scr</goal>
107 + </goals>
108 + </execution>
109 + </executions>
110 + <configuration>
111 + <!-- avoid searching into wrong source path -->
112 + <scanClasses>true</scanClasses>
113 + <supportedProjectTypes>
114 + <supportedProjectType>bundle</supportedProjectType>
115 + <supportedProjectType>war</supportedProjectType>
116 + </supportedProjectTypes>
117 + </configuration>
118 + </plugin>
119 + </plugins>
120 + </build>
121 +
122 +</project>
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.incubator.rpc.nb.impl;
18 +
19 +import io.grpc.Server;
20 +import io.grpc.netty.NettyServerBuilder;
21 +import org.apache.felix.scr.annotations.Activate;
22 +import org.apache.felix.scr.annotations.Component;
23 +import org.apache.felix.scr.annotations.Deactivate;
24 +import org.apache.felix.scr.annotations.Reference;
25 +import org.apache.felix.scr.annotations.ReferenceCardinality;
26 +import org.onosproject.incubator.rpc.nb.mcast.MulticastRouteGrpcService;
27 +import org.onosproject.net.mcast.MulticastRouteService;
28 +import org.slf4j.Logger;
29 +import org.slf4j.LoggerFactory;
30 +
31 +import java.io.IOException;
32 +
33 +/**
34 + * gRPC server for northbound APIs.
35 + */
36 +@Component(immediate = true)
37 +public class GrpcServer {
38 +
39 + private final Logger log = LoggerFactory.getLogger(getClass());
40 +
41 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
42 + protected MulticastRouteService multicastRouteService;
43 +
44 + // TODO make configurable
45 + private int port = 50051;
46 +
47 + private Server server;
48 +
49 + @Activate
50 + public void activate() {
51 + start();
52 + log.info("Started");
53 + }
54 +
55 + @Deactivate
56 + public void deactivate() {
57 + stop();
58 + log.info("Stopped");
59 + }
60 +
61 + private void start() {
62 + try {
63 + server = NettyServerBuilder.forPort(port)
64 + .addService(new MulticastRouteGrpcService(multicastRouteService))
65 + .build()
66 + .start();
67 + log.info("gRPC server started listening on " + port);
68 + } catch (IOException e) {
69 + log.error("Failed to start gRPC server", e);
70 + }
71 + }
72 +
73 + private void stop() {
74 + if (server != null) {
75 + server.shutdown();
76 + }
77 + }
78 +}
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +/**
18 + * Northbound gPRC implementation.
19 + */
20 +package org.onosproject.incubator.rpc.nb.impl;
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.incubator.rpc.nb.mcast;
18 +
19 +import io.grpc.stub.StreamObserver;
20 +import org.onlab.packet.IpAddress;
21 +import org.onosproject.grpc.net.mcast.MulticastRouteServiceGrpc;
22 +import org.onosproject.grpc.net.mcast.MulticastRouteServiceOuterClass;
23 +import org.onosproject.net.mcast.McastRoute;
24 +import org.onosproject.net.mcast.MulticastRouteService;
25 +import org.slf4j.Logger;
26 +import org.slf4j.LoggerFactory;
27 +
28 +import com.google.common.annotations.Beta;
29 +
30 +/**
31 + * Implementation of multicast gRPC service.
32 + */
33 +@Beta
34 +public class MulticastRouteGrpcService
35 + extends MulticastRouteServiceGrpc.MulticastRouteServiceImplBase {
36 +
37 + private final Logger log = LoggerFactory.getLogger(getClass());
38 +
39 + private final MulticastRouteService multicastRouteService;
40 +
41 + public MulticastRouteGrpcService(MulticastRouteService service) {
42 + this.multicastRouteService = service;
43 + }
44 +
45 + @Override
46 + public StreamObserver<MulticastRouteServiceOuterClass.MulticastRequest>
47 + operation(StreamObserver<MulticastRouteServiceOuterClass.MulticastReply> responseObserver) {
48 +
49 + return new MulticastServiceServerProxy(responseObserver);
50 + }
51 +
52 + private final class MulticastServiceServerProxy
53 + implements StreamObserver<MulticastRouteServiceOuterClass.MulticastRequest> {
54 +
55 + private final StreamObserver<MulticastRouteServiceOuterClass.MulticastReply> responseObserver;
56 +
57 + public MulticastServiceServerProxy(
58 + StreamObserver<MulticastRouteServiceOuterClass.MulticastReply> responseObserver) {
59 + this.responseObserver = responseObserver;
60 + }
61 +
62 + @Override
63 + public void onNext(MulticastRouteServiceOuterClass.MulticastRequest value) {
64 + MulticastRouteServiceOuterClass.MulticastRoute route = value.getRoute();
65 +
66 + switch (value.getOperation()) {
67 + case ADD_ROUTE:
68 + multicastRouteService.add(
69 + new McastRoute(IpAddress.valueOf(route.getSource()),
70 + IpAddress.valueOf(route.getGroup()),
71 + McastRoute.Type.STATIC));
72 + break;
73 + case ADD_SOURCE:
74 + break;
75 + case ADD_SINK:
76 + break;
77 + case REMOVE_ROUTE:
78 + break;
79 + case REMOVE_SOURCE:
80 + break;
81 + case REMOVE_SINK:
82 + break;
83 + case UNRECOGNIZED:
84 + default:
85 + break;
86 + }
87 +
88 + responseObserver.onNext(MulticastRouteServiceOuterClass.MulticastReply.newBuilder().build());
89 + }
90 +
91 + @Override
92 + public void onError(Throwable t) {
93 + log.warn("Error receiving multicast route", t);
94 + }
95 +
96 + @Override
97 + public void onCompleted() {
98 + // When the client closes their stream, we'll close ours too
99 + responseObserver.onCompleted();
100 + }
101 + }
102 +}
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +/**
18 + * Multicast gRPC implementation.
19 + */
20 +package org.onosproject.incubator.rpc.nb.mcast;