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 "mirror_kstate.h" 8 : #include "vr_mirror.h" 9 : 10 : using namespace std; 11 : 12 0 : MirrorKState::MirrorKState(KMirrorResp *obj, const std::string &resp_ctx, 13 0 : vr_mirror_req &req, int id): KState(resp_ctx, obj) { 14 : 15 0 : req.set_mirr_index(id); 16 0 : if (id >= 0) { 17 0 : req.set_h_op(sandesh_op::GET); 18 : } else { 19 0 : req.set_h_op(sandesh_op::DUMP); 20 0 : req.set_mirr_marker(-1); 21 : } 22 0 : } 23 : 24 0 : void MirrorKState::SendNextRequest() { 25 0 : vr_mirror_req req; 26 : 27 0 : req.set_mirr_index(0); 28 0 : req.set_h_op(sandesh_op::DUMP); 29 0 : int32_t idx = boost::any_cast<int32_t>(more_context_); 30 0 : req.set_mirr_marker(idx); 31 0 : EncodeAndSend(req); 32 0 : } 33 : 34 0 : void MirrorKState::Handler() { 35 0 : KMirrorResp *resp = static_cast<KMirrorResp *>(response_object_); 36 0 : if (resp) { 37 0 : if (MoreData()) { 38 : /* There are more nexthops in Kernel. We need to query them from 39 : * Kernel and send it to Sandesh. 40 : */ 41 0 : SendResponse(); 42 0 : SendNextRequest(); 43 : } else { 44 0 : resp->set_context(response_context_); 45 0 : resp->Response(); 46 0 : more_context_ = boost::any(); 47 : } 48 : } 49 0 : } 50 : 51 0 : void MirrorKState::SendResponse() { 52 : 53 0 : KMirrorResp *resp = static_cast<KMirrorResp *>(response_object_); 54 0 : resp->set_context(response_context_); 55 0 : resp->set_more(true); 56 0 : resp->Response(); 57 : 58 0 : response_object_ = new KMirrorResp(); 59 0 : } 60 : 61 0 : const string MirrorKState::FlagsToString(int flags) const { 62 0 : if (flags == 0) { 63 0 : return "NIL"; 64 : } 65 0 : if (flags & VR_MIRROR_FLAG_MARKED_DELETE) { 66 0 : return "MARKED_DELETE"; 67 : } 68 0 : return "INVALID"; 69 : }