VOL-1114 Flow removal implementation

Change-Id: Ia2bb06e0e762fe87abbb4f25849c79cd07191395
diff --git a/protos/openolt.proto b/protos/openolt.proto
index c4d4fd0..00509f6 100644
--- a/protos/openolt.proto
+++ b/protos/openolt.proto
@@ -81,6 +81,13 @@
         };
     }
 
+    rpc FlowRemove(Flow) returns (Empty) {
+        option (google.api.http) = {
+          post: "/v1/FlowRemove"
+          body: "*"
+        };
+    }
+
     rpc HeartbeatCheck(Empty) returns (Heartbeat) {
         option (google.api.http) = {
           post: "/v1/HeartbeatCheck"
diff --git a/src/core.cc b/src/core.cc
index eacbf27..9ad075c 100644
--- a/src/core.cc
+++ b/src/core.cc
@@ -638,6 +638,36 @@
     return Status::OK;
 }
 
+Status FlowRemove_(uint32_t flow_id, const std::string flow_type) {
+
+    bcmbal_flow_cfg cfg;
+    bcmbal_flow_key key = { };
+
+    key.flow_id = (bcmbal_flow_id) flow_id;
+    key.flow_id = flow_id;
+    if (flow_type.compare("upstream") == 0 ) {
+        key.flow_type = BCMBAL_FLOW_TYPE_UPSTREAM;
+    } else if (flow_type.compare("downstream") == 0) {
+        key.flow_type = BCMBAL_FLOW_TYPE_DOWNSTREAM;
+    } else {
+        std::cout << "Invalid flow type " << flow_type << std::endl;
+        return bcm_to_grpc_err(BCM_ERR_PARM, "Invalid flow type");
+    }
+
+    BCMBAL_CFG_INIT(&cfg, flow, key);
+
+
+    bcmos_errno err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &cfg.hdr);
+    if (err) {
+        std::cout << "Error " << err << " while removing flow "
+            << flow_id << ", " << flow_type << std::endl;
+        return Status(grpc::StatusCode::INTERNAL, "Failed to remove flow");
+    }
+
+    std::cout << "Flow " << flow_id << ", " << flow_type << " removed";
+    return Status::OK;
+}
+
 Status SchedAdd_(int intf_id, int onu_id, int agg_port_id) {
     bcmbal_tm_sched_cfg cfg;
     bcmbal_tm_sched_key key = { };
diff --git a/src/core.h b/src/core.h
index 182b06d..2890eb3 100644
--- a/src/core.h
+++ b/src/core.h
@@ -42,6 +42,7 @@
                 uint32_t gemport_id, uint32_t priority,
                 const ::openolt::Classifier& classifier,
                 const ::openolt::Action& action);
+Status FlowRemove_(uint32_t flow_id, const std::string flow_type);
 Status Disable_();
 Status Reenable_();
 
diff --git a/src/server.cc b/src/server.cc
index 5c46332..709eb31 100644
--- a/src/server.cc
+++ b/src/server.cc
@@ -138,6 +138,15 @@
             request->action());
     }
 
+    Status FlowRemove(
+            ServerContext* context,
+            const openolt::Flow* request,
+            openolt::Empty* response) override {
+        return FlowRemove_(
+            request->flow_id(),
+            request->flow_type());
+    }
+
     Status EnableIndication(
             ServerContext* context,
             const ::openolt::Empty* request,