Skip to content

Commit

Permalink
release 0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
adibrastegarnia committed Feb 22, 2019
1 parent 009bd99 commit 5fe9292
Show file tree
Hide file tree
Showing 9 changed files with 239 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2019-present Open Networking Foundation
*
* 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.grpcintegration.api;

/**
* API for gRPC Device Service.
*/
public interface DevicegrpcService {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
* Copyright 2019-present Open Networking Foundation
*
* 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.grpcintegration.app;

import io.grpc.stub.StreamObserver;
import org.onlab.osgi.DefaultServiceDirectory;
import org.onlab.packet.IpAddress;
import org.onosproject.grpc.grpcintegration.models.ControlMessagesProto.Ports;
import org.onosproject.grpc.grpcintegration.models.ControlMessagesProto.DeviceCountProto;
import org.onosproject.grpc.grpcintegration.models.ControlMessagesProto.Devices;
import org.onosproject.grpc.grpcintegration.models.ControlMessagesProto.Empty;
import org.onosproject.grpc.grpcintegration.models.DeviceServiceGrpc.DeviceServiceImplBase;
import org.onosproject.grpc.net.models.DeviceIdProtoOuterClass.DeviceIdProto;
import org.onosproject.grpc.net.models.DeviceProtoOuterClass.DeviceProto;
import org.onosproject.grpcintegration.api.DevicegrpcService;


import org.onosproject.incubator.protobuf.models.net.ConnectPointProtoTranslator;
import org.onosproject.incubator.protobuf.models.net.device.PortProtoTranslator;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Port;
import org.onosproject.net.device.DeviceService;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.slf4j.Logger;

import java.util.List;

import static org.slf4j.LoggerFactory.getLogger;

/**
* Implements gRPC Device Service.
*/
@Component(immediate = true, service = DevicegrpcService.class)
public class DeviceServiceManager
extends DeviceServiceImplBase
implements DevicegrpcService {

private final Logger log = getLogger(getClass());

@Reference(cardinality = ReferenceCardinality.MANDATORY)
protected DeviceService deviceService;


@Activate
protected void activate() {

log.info("Device Service has been activated");
}

@Deactivate
protected void deactivate() {

log.info("Device Service has been deactivated");
}

@Override
public void getDevices (Empty empty, StreamObserver<Devices> observer) {
// TODO: DeviceProtoTranslator needs to be completed.

}

/**
* Returns number of Devices in the network topology.
* @param empty {@link Empty}
* @param observer {@link DeviceCountProto}
*/
@Override
public void getDeviceCount (Empty empty, StreamObserver<DeviceCountProto> observer) {
deviceService = DefaultServiceDirectory.getService(DeviceService.class);
DeviceCountProto deviceCountProto = DeviceCountProto
.newBuilder()
.setCount(deviceService.getDeviceCount()).build();

observer.onNext(deviceCountProto);
observer.onCompleted();
}

@Override
public void getDevice (DeviceIdProto deviceIdProto,
StreamObserver<DeviceProto> observer) {
deviceService = DefaultServiceDirectory.getService(DeviceService.class);
Device device = deviceService.getDevice(DeviceId.deviceId(deviceIdProto.getDeviceId()));

//TODO: DeviceProto Translator is needed

}

@Override
public void getPorts(DeviceIdProto deviceIdProto, StreamObserver<Ports> observer) {

deviceService = DefaultServiceDirectory.getService(DeviceService.class);
Ports.Builder portsBuilder = Ports.newBuilder();

List<Port> ports = deviceService.getPorts(DeviceId.deviceId(deviceIdProto.getDeviceId()));

for (Port port:ports) {
//TODO: PortProtoTranslator needs to be completed.
}

}





}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.onosproject.grpc.grpcintegration.models.EventNotificationProto.RegistrationResponse;
import org.onosproject.grpc.grpcintegration.models.EventNotificationProto.Topic;
import org.onosproject.grpc.grpcintegration.models.EventNotificationProto.topicType;
import org.onosproject.grpc.net.device.models.DeviceEventProto;
import org.onosproject.grpc.net.link.models.LinkEventProto.LinkNotificationProto;
import org.onosproject.grpc.net.packet.models.PacketContextProtoOuterClass.PacketContextProto;
import org.onosproject.grpcintegration.api.EventNotificationService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ private void start() throws IOException {
.addService(new FlowServiceManager())
.addService(new TopologyServiceManager())
.addService(new HostServiceManager())
.addService(new DeviceServiceManager())
.build()
.start();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@
import org.onosproject.grpc.grpcintegration.models.ControlMessagesProto.HostCountProto;
import org.onosproject.grpc.grpcintegration.models.ControlMessagesProto.Hosts;
import org.onosproject.grpc.grpcintegration.models.ControlMessagesProto.Empty;
import org.onosproject.grpc.net.models.ConnectPointProtoOuterClass.ConnectPointProto;
import org.onosproject.grpc.net.models.DeviceIdProtoOuterClass.DeviceIdProto;
import org.onosproject.grpc.net.models.HostIdProtoOuterClass.HostIdProto;
import org.onosproject.grpc.net.models.HostProtoOuterClass.HostProto;
import org.onosproject.grpcintegration.api.HostgrpcService;
import org.onosproject.incubator.protobuf.models.net.ConnectPointProtoTranslator;
import org.onosproject.incubator.protobuf.models.net.HostIdProtoTranslator;
import org.onosproject.incubator.protobuf.models.net.HostProtoTranslator;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Host;
import org.onosproject.net.host.HostService;
import org.osgi.service.component.annotations.Activate;
Expand All @@ -36,6 +41,10 @@
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.slf4j.Logger;

import java.util.List;
import java.util.Optional;
import java.util.Set;

import static org.slf4j.LoggerFactory.getLogger;

/**
Expand Down Expand Up @@ -118,4 +127,50 @@ public void getHost (HostIdProto hostIdProto,
observer.onCompleted();
}

/**
* Returns list of hosts by DeviceId.
* @param deviceIdProto {@link DeviceIdProto}
* @param observer {@link Hosts}
*/
@Override
public void getConnectedHostsByDeviceId (DeviceIdProto deviceIdProto,
StreamObserver<Hosts> observer) {

hostService = DefaultServiceDirectory.getService(HostService.class);
Hosts.Builder hostsProtoBuilder = Hosts.newBuilder();
Set<Host> hosts = hostService
.getConnectedHosts(DeviceId.deviceId(deviceIdProto.getDeviceId()));

for(Host host: hosts) {
hostsProtoBuilder.addHost(HostProtoTranslator.translate(host));
}

observer.onNext(hostsProtoBuilder.build());
observer.onCompleted();
}

/**
* Returns list of hosts by ConnectedPoint.
* @param connectPointProto {@link ConnectPointProto}
* @param observer {@link Hosts}
*/
@Override
public void getConnectedHostsByConnectedPoint (ConnectPointProto connectPointProto,
StreamObserver<Hosts> observer) {

hostService = DefaultServiceDirectory.getService(HostService.class);
Hosts.Builder hostsProtoBuilder = Hosts.newBuilder();
Optional<ConnectPoint> connectPoint = ConnectPointProtoTranslator
.translate(connectPointProto);
Set<Host> hosts = hostService.getConnectedHosts(connectPoint.get());

for(Host host: hosts) {
hostsProtoBuilder.addHost(HostProtoTranslator.translate(host));
}

observer.onNext(hostsProtoBuilder.build());
observer.onCompleted();

}

}
9 changes: 7 additions & 2 deletions grpc-integration/protobuf/models/proto/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ proto_library(
":Device_proto",
":Host_proto",
":Path_proto",
":Port_proto",
":TopologyCluster_proto",
":Topology_proto",
],
Expand All @@ -118,15 +119,19 @@ proto_library(
srcs = ["grpcintegration/ServicesProto.proto"],
proto_source_root = PROTO_SOURCE_ROOT,
deps = [
":ConnectPoint_proto",
":ControlMessages_proto",
":DeviceId_proto",
":Device_proto",
":EventNotification_proto",
":FlowRule_proto",
":HostId_proto",
":Host_proto",
":OutboundPacket_proto",
":Port_proto",
":Status_proto",
":TopologyGraph_proto",
":Topology_proto",
":Host_proto",
":HostId_proto"
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import "apps/grpc-integration/protobuf/models/proto/net/HostProto.proto";
import "apps/grpc-integration/protobuf/models/proto/net/topology/ClusterIdProto.proto";
import "apps/grpc-integration/protobuf/models/proto/net/topology/TopologyClusterProto.proto";
import "apps/grpc-integration/protobuf/models/proto/net/topology/TopologyProto.proto";
import "apps/grpc-integration/protobuf/models/proto/net/PortProto.proto";

message Empty {

Expand Down Expand Up @@ -42,4 +43,17 @@ message Hosts {

message HostCountProto {
int32 count = 1;
}

// Related to DeviceService
message DeviceCountProto {
int32 count = 1;
}

message Devices {
repeated net.DeviceProto device = 1;
}

message Ports {
repeated net.PortProto port = 1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import "apps/grpc-integration/protobuf/models/proto/grpcintegration/StatusProto.
import "apps/grpc-integration/protobuf/models/proto/grpcintegration/ControlMessagesProto.proto";
import "apps/grpc-integration/protobuf/models/proto/net/HostProto.proto";
import "apps/grpc-integration/protobuf/models/proto/net/HostIdProto.proto";
import "apps/grpc-integration/protobuf/models/proto/net/PortProto.proto";
import "apps/grpc-integration/protobuf/models/proto/net/DeviceIdProto.proto";
import "apps/grpc-integration/protobuf/models/proto/net/DeviceProto.proto";
import "apps/grpc-integration/protobuf/models/proto/net/ConnectPointProto.proto";


// Corresponds to PacketOut service
Expand All @@ -37,12 +41,17 @@ service HostService {
rpc getHosts (Empty) returns (Hosts);
rpc getHostCount (Empty) returns (HostCountProto);
rpc getHost (net.HostIdProto) returns (net.HostProto);
rpc getConnectedHostsByDeviceId (net.DeviceIdProto) returns (Hosts);
rpc getConnectedHostsByConnectedPoint (net.ConnectPointProto) returns (Hosts);

}

// Corresponds to Device Service
service DeviceService {

rpc getDeviceCount (Empty) returns (DeviceCountProto);
rpc getDevices (Empty) returns (Devices);
rpc getPorts (net.DeviceIdProto) returns (Ports);
rpc getDevice (net.DeviceIdProto) returns (net.DeviceProto);
}

// Corresponds to Core Service
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.onosproject.incubator.protobuf.models.net.link;

import org.onosproject.grpc.net.link.models.LinkEnumsProto;
import org.onosproject.grpc.net.link.models.LinkEventProto;
import org.onosproject.grpc.net.link.models.LinkEventProto.LinkNotificationProto;
import org.onosproject.grpc.net.models.ConnectPointProtoOuterClass;
import org.onosproject.grpc.net.models.LinkProtoOuterClass;
import org.onosproject.net.link.LinkEvent;
Expand Down Expand Up @@ -29,10 +29,10 @@ private static LinkEnumsProto.LinkEventTypeProto getProtoType(LinkEvent event) {



public static LinkEventProto.LinkNotificationProto translate(LinkEvent linkEvent)
public static LinkNotificationProto translate(LinkEvent linkEvent)
{

LinkEventProto.LinkNotificationProto notification = LinkEventProto.LinkNotificationProto.newBuilder()
LinkNotificationProto notification = LinkNotificationProto.newBuilder()
.setLinkEventType(getProtoType(linkEvent))
.setLink(LinkProtoOuterClass.LinkProto.newBuilder()
.setState(LinkEnumsProto.LinkStateProto.ACTIVE
Expand Down

0 comments on commit 5fe9292

Please sign in to comment.