Line data Source code
1 : /* 2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. 3 : * Copyright Contributors to the OpenSDN project 4 : */ 5 : 6 : #include "kstate.h" 7 : #include "vrf_kstate.h" 8 : 9 0 : VrfKState::VrfKState(KVrfResp *obj, 10 : const std::string &resp_ctx, 11 0 : vr_vrf_req &req, int id) : 12 0 : KState(resp_ctx, obj) { 13 : 14 0 : req.set_h_op(sandesh_op::DUMP); 15 0 : req.set_vrf_idx(id); 16 0 : req.set_vrf_marker(-1); 17 0 : } 18 : 19 0 : void VrfKState::SendNextRequest() { 20 0 : VrfContext *ctx = boost::any_cast<VrfContext *>(more_context_); 21 0 : vr_vrf_req req; 22 : 23 0 : req.set_h_op(sandesh_op::DUMP); 24 0 : req.set_vrf_idx(ctx->vrf_idx_); 25 0 : req.set_vrf_hbfl_vif_idx(ctx->hbf_lintf_); 26 0 : req.set_vrf_hbfr_vif_idx(ctx->hbf_rintf_); 27 0 : req.set_vrf_marker(ctx->marker_); 28 0 : EncodeAndSend(req); 29 0 : } 30 : 31 0 : void VrfKState::Handler() { 32 0 : KVrfResp *resp = static_cast<KVrfResp *>(response_object_); 33 0 : if (resp) { 34 0 : if (MoreData()) { 35 : /* There are more labels in Kernel. We need to query them from 36 : * Kernel and send it to Sandesh. 37 : */ 38 0 : SendResponse(); 39 0 : SendNextRequest(); 40 : } else { 41 0 : resp->set_context(response_context_); 42 0 : resp->Response(); 43 0 : if (!more_context_.empty()) { 44 : VrfContext *ctx = 45 0 : boost::any_cast<VrfContext *>(more_context_); 46 0 : if (ctx) { 47 0 : delete ctx; 48 0 : more_context_ = boost::any(); 49 : } 50 : } 51 : } 52 : } 53 0 : } 54 : 55 0 : void VrfKState::SendResponse() { 56 0 : KVrfResp *resp = static_cast<KVrfResp *>(response_object_); 57 0 : resp->set_context(response_context_); 58 0 : resp->set_more(true); 59 0 : resp->Response(); 60 : 61 0 : response_object_ = new KVrfResp(); 62 0 : }