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