Skip to content

Commit

Permalink
TopologyEdgeProto translator has been updated to support port numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
adibrastegarnia committed Feb 12, 2019
1 parent a962f56 commit 3beb7be
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,19 @@ public void addFlow(FlowRuleProto flowRuleRequest,

flowRuleService = DefaultServiceDirectory.getService(FlowRuleService.class);
coreService = DefaultServiceDirectory.getService(CoreService.class);
FlowRule.Builder flowRule = FlowRuleProtoTranslator.translate(flowRuleRequest);
FlowRule flowRule = null;

if (flowRuleRequest.getAppName() != null) {
ApplicationId applicationId = coreService.registerApplication(flowRuleRequest.getAppName());
flowRule.fromApp(applicationId);
flowRule = FlowRuleProtoTranslator.translate(applicationId,flowRuleRequest);
}

if(flowRule == null) {
log.error("Format of flow rule is not correct");
return;
}

flowRuleService.applyFlowRules(flowRule.build());
flowRuleService.applyFlowRules(flowRule);

FlowServiceStatus flowServiceStatus = FlowServiceStatus
.newBuilder().setStat(true).build();
Expand All @@ -90,19 +95,24 @@ public void removeFlow(FlowRuleProto flowRuleRequest,
StreamObserver<FlowServiceStatus> responseObserver) {
flowRuleService = DefaultServiceDirectory.getService(FlowRuleService.class);

FlowRule.Builder flowRule = FlowRuleProtoTranslator.translate(flowRuleRequest);
FlowRule flowRule = null;

if (flowRuleRequest.getAppName() != null) {
ApplicationId applicationId = coreService.registerApplication(flowRuleRequest.getAppName());
flowRule.fromApp(applicationId);
ApplicationId applicationId = coreService
.registerApplication(flowRuleRequest.getAppName());
flowRule = FlowRuleProtoTranslator.translate(applicationId,flowRuleRequest);
}

flowRuleService.removeFlowRules(flowRule.build());
if(flowRule == null) {
log.error("Format of flow rule is not correct");
return;
}

flowRuleService.removeFlowRules(flowRule);
FlowServiceStatus flowServiceStatus = FlowServiceStatus
.newBuilder().setStat(true).build();
responseObserver.onNext(flowServiceStatus);
responseObserver.onCompleted();


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@



import org.onosproject.core.ApplicationId;
import org.onosproject.grpc.net.flow.models.FlowRuleProto;
import org.onosproject.net.DeviceId;
import org.onosproject.net.flow.DefaultFlowRule;
Expand Down Expand Up @@ -63,19 +64,22 @@ public static FlowRuleProto translate(FlowRule flowRule) {
* @param flowRule gRPC message
* @return {@link FlowRule}
*/
public static FlowRule.Builder translate(FlowRuleProto flowRule) {
public static FlowRule translate(ApplicationId applicationId,
FlowRuleProto flowRule) {

if (flowRule.equals(FlowRuleProto.getDefaultInstance())) {
return null;
}

DeviceId deviceId = DeviceId.deviceId(flowRule.getDeviceId());


FlowRule.FlowRemoveReason reason =
FlowRuleEnumsProtoTranslator.translate(flowRule.getReason()).get();

FlowRule.Builder resultBuilder = new DefaultFlowRule.Builder();

resultBuilder.fromApp(applicationId);
resultBuilder.forDevice(deviceId);
resultBuilder.forTable(flowRule.getTableId());
resultBuilder.withPriority(flowRule.getPriority());
Expand All @@ -91,7 +95,7 @@ public static FlowRule.Builder translate(FlowRuleProto flowRule) {
resultBuilder.makeTemporary(flowRule.getTimeout());
}

return resultBuilder;
return resultBuilder.build();
}

// Utility class not intended for instantiation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@ public static TopologyEdgeProto translate(TopologyEdge topologyEdge) {
ConnectPointProto srcConnectPointProto = ConnectPointProto
.newBuilder()
.setDeviceId(topologyEdge.link().src().deviceId().toString())
.setPortNumber(topologyEdge.link().src().port().name())
.build();

ConnectPointProto dstConnectPointProto = ConnectPointProto
.newBuilder()
.setDeviceId(topologyEdge.link().dst().deviceId().toString())
.setPortNumber(topologyEdge.link().dst().port().name())
.build();

LinkStateProto linkStateProto = LinkStateProto
Expand Down

0 comments on commit 3beb7be

Please sign in to comment.