Skip to content
This repository was archived by the owner on Mar 31, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 114 additions & 0 deletions tools/grpc-sample/program/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<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>
<groupId>io.grpc</groupId>
<artifactId>simple-grpc</artifactId>
<packaging>jar</packaging>
<version>0.0.1</version><!-- CURRENT_GRPC_VERSION -->
<name>simple-grpc</name>
<url>https://futurewei.com</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<grpc.version>1.29.0</grpc.version><!-- CURRENT_GRPC_VERSION -->
<protoc.version>3.11.0</protoc.version>
<netty.tcnative.version>2.0.30.Final</netty.tcnative.version>
<!-- required for jdk9 -->
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-bom</artifactId>
<version>${grpc.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>

<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-protobuf</artifactId>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-stub</artifactId>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.2</version>
<scope>provided</scope> <!-- not needed at runtime -->
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty</artifactId>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative-boringssl-static</artifactId>
<version>${netty.tcnative.version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>

<build>
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.6.2</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.6.1</version>
<configuration>
<protocArtifact>com.google.protobuf:protoc:${protoc.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.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<excludes>
<exclude>org.apache.tomcat.embed:*</exclude>
</excludes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.grpc.examples.helloworld;

import io.grpc.Server;
import io.grpc.ServerBuilder;

public class GrpcServer {
public static void main(String[] args) {
try {

int port = Integer.parseInt(args[0]);
final Server server =
ServerBuilder.forPort(port).addService(new HelloServiceImpl()).build().start();
System.out.println("Server started, listening on " + port);
server.awaitTermination();

} catch (Exception e) {
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.grpc.examples.helloworld;

import com.futurewei.alcor.schema.GoalStateProvisionerGrpc;
import com.futurewei.alcor.schema.Goalstate;
import com.futurewei.alcor.schema.Goalstateprovisioner;
import io.grpc.stub.StreamObserver;

public class HelloServiceImpl extends GoalStateProvisionerGrpc.GoalStateProvisionerImplBase {
@Override
public void pushNetworkResourceStates(
Goalstate.GoalState request,
StreamObserver<Goalstateprovisioner.GoalStateOperationReply> responseObserver) {
final Goalstateprovisioner.GoalStateOperationReply build =
Goalstateprovisioner.GoalStateOperationReply.newBuilder().build();
responseObserver.onNext(build);
responseObserver.onCompleted();
}
}
71 changes: 71 additions & 0 deletions tools/grpc-sample/program/src/main/proto/common.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
Copyright 2019 The Alcor Authors.

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.
*/

syntax = "proto3";

package alcor.schema;

option java_package = "com.futurewei.alcor.schema";
option java_outer_classname = "Common";

enum ResourceType {
VPC = 0;
SUBNET = 1;
PORT = 2;
NEIGHBOR = 3;
SECURITYGROUP = 4;
DHCP = 5;
ROUTER = 6;
}

enum OperationType {
CREATE = 0;
UPDATE = 1;
GET = 2;
DELETE = 3;
INFO = 4;
NEIGHBOR_CREATE_UPDATE = 5; // To be removed after using NeighborState
NEIGHBOR_GET = 6; // To be removed after using NeighborState
NEIGHBOR_DELETE = 7; // To be removed after using NeighborState
}

enum OperationStatus {
SUCCESS = 0;
FAILURE = 1;
INVALID_ARG = 2;
PENDING = 3;
}

enum EtherType {
IPV4 = 0;
IPV6 = 1;
}

enum Protocol {
TCP = 0;
UDP = 1;
ICMP = 2;
HTTP = 3;
ARP = 4;
}

enum NetworkType {
VXLAN = 0; // the default type
VLAN = 1;
GRE = 2;
GENEVE = 3;
VXLAN_GPE = 4;
}
53 changes: 53 additions & 0 deletions tools/grpc-sample/program/src/main/proto/dhcp.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
Copyright 2019 The Alcor Authors.

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.
*/

syntax = "proto3";

package alcor.schema;

option java_package = "com.futurewei.alcor.schema";
option java_outer_classname = "DHCP";

import "common.proto";

message DHCPConfiguration {
uint32 format_version = 1;
uint32 revision_number = 2;

string request_id = 3;
string subnet_id = 4;
string mac_address = 5;
string ipv4_address = 6;
string ipv6_address = 7;
string port_host_name = 8; // for local DNS response

message ExtraDhcpOption {
string name = 1;
string value = 2;
}

message DnsEntry {
string entry = 1;
}

repeated ExtraDhcpOption extra_dhcp_options = 9;
repeated DnsEntry dns_entry_list = 10;
}

message DHCPState {
OperationType operation_type = 1;
DHCPConfiguration configuration = 2;
}
41 changes: 41 additions & 0 deletions tools/grpc-sample/program/src/main/proto/goalstate.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
Copyright 2019 The Alcor Authors.

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.
*/

syntax = "proto3";

package alcor.schema;

option java_package = "com.futurewei.alcor.schema";

import "vpc.proto";
import "subnet.proto";
import "port.proto";
import "neighbor.proto";
import "securitygroup.proto";
import "dhcp.proto";
import "router.proto";

message GoalState {
uint32 format_version = 1;

repeated VpcState vpc_states = 2;
repeated SubnetState subnet_states = 3;
repeated PortState port_states = 4;
repeated NeighborState neighbor_states = 5;
repeated SecurityGroupState security_group_states = 6;
repeated DHCPState dhcp_states = 7;
repeated RouterState router_states = 8;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
Copyright 2019 The Alcor Authors.

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.
*/

syntax = "proto3";

package alcor.schema;

option java_package = "com.futurewei.alcor.schema";

import "common.proto";
import "goalstate.proto";

service GoalStateProvisioner {

// Push a group of network resource states
//
// Input: a GoalState object consists of a list of operation requests, and each request contains an operation type and a resource configuration
// Results consist of a list of operation statuses, and each status is a response to one operation request in the input
//
// Note: It is a NoOps for Control Agents when the operation type is INFO or GET.
// Use RetrieveNetworkResourceStates for state query.
rpc PushNetworkResourceStates (GoalState) returns (GoalStateOperationReply) {
}

// Retrieve a group of network resource states (stored as a steam of GoalState objects)
rpc RetrieveNetworkResourceStates (GoalStateRequest) returns (stream GoalState) {
}
}

message GoalStateRequest {
uint32 format_version = 1;

message ResourceStateRequest {
string resource_id = 1;
ResourceType resource_type = 2;
}

repeated ResourceStateRequest state_requests = 2;
}

message GoalStateOperationReply {
uint32 format_version = 1;

message GoalStateOperationStatus {
string resource_id = 1;
ResourceType resource_type = 2;
OperationType operation_type = 3;
OperationStatus operation_status = 4;
uint32 dataplane_programming_time = 5;
uint32 network_configuration_time = 6;
uint32 state_elapse_time = 7;
}

repeated GoalStateOperationStatus operation_statuses = 2;

// Total operation time (in nanoseconds)
// 1. to process the message (consisting of multiple operations)
// 2. to program data plane
// Note: The list of operation_statuses details the time spent at each operation
uint32 message_total_operation_time = 3;
}
Loading