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 "mpls_kstate.h" 8 : 9 0 : MplsKState::MplsKState(KMplsResp *obj, const std::string &resp_ctx, 10 0 : vr_mpls_req &req, int id) : KState(resp_ctx, obj) { 11 0 : req.set_mr_label(id); 12 0 : if (id >= 0) { 13 0 : req.set_h_op(sandesh_op::GET); 14 : } else { 15 0 : req.set_h_op(sandesh_op::DUMP); 16 0 : req.set_mr_marker(-1); 17 : } 18 0 : } 19 : 20 0 : void MplsKState::SendNextRequest() { 21 0 : vr_mpls_req req; 22 0 : req.set_h_op(sandesh_op::DUMP); 23 0 : req.set_mr_label(0); 24 0 : int32_t label = boost::any_cast<int32_t>(more_context_); 25 0 : req.set_mr_marker(label); 26 0 : EncodeAndSend(req); 27 0 : } 28 : 29 0 : void MplsKState::Handler() { 30 0 : KMplsResp *resp = static_cast<KMplsResp *>(response_object_); 31 0 : if (resp) { 32 0 : if (MoreData()) { 33 : /* There are more labels in Kernel. We need to query them from 34 : * Kernel and send it to Sandesh. 35 : */ 36 0 : SendResponse(); 37 0 : SendNextRequest(); 38 : } else { 39 0 : resp->set_context(response_context_); 40 0 : resp->Response(); 41 0 : more_context_ = boost::any(); 42 : } 43 : } 44 0 : } 45 : 46 0 : void MplsKState::SendResponse() { 47 : 48 0 : KMplsResp *resp = static_cast<KMplsResp *>(response_object_); 49 0 : resp->set_context(response_context_); 50 0 : resp->set_more(true); 51 0 : resp->Response(); 52 : 53 0 : response_object_ = new KMplsResp(); 54 0 : }