diff options
Diffstat (limited to 'src/include/VppInspect.hpp')
-rw-r--r-- | src/include/VppInspect.hpp | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/src/include/VppInspect.hpp b/src/include/VppInspect.hpp new file mode 100644 index 0000000..3b765d1 --- /dev/null +++ b/src/include/VppInspect.hpp @@ -0,0 +1,126 @@ +/* -*- C++ -*-; c-basic-offset: 4; indent-tabs-mode: nil */ +/* + * Copyright (c) 2017 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +#pragma once +#ifndef VPP_INSPECT_H +#define VPP_INSPECT_H + +#include <map> +#include <sstream> +#include <string> +#include <uv.h> +#include <vector> + +#include "vom/inspect.hpp" + +namespace opflexagent +{ +/** + * A means to inspect the state VPP has built, in total, and per-client + * To use do: + * socat - UNIX-CONNECT:/path/to/sock/in/opflex.conf + * and follow the instructions + */ +class VppInspect +{ + public: + /** + * Constructor + */ + VppInspect(const std::string &sockname); + + /** + * Destructor to tidyup socket resources + */ + ~VppInspect(); + + private: + /** + * Call operator for running in the thread + */ + static void run(void *ctx); + + /** + * A write request + */ + struct write_req_t + { + write_req_t(std::ostringstream &output); + ~write_req_t(); + + uv_write_t req; + uv_buf_t buf; + }; + + /** + * Write a ostream to the client + */ + static void do_write(uv_stream_t *client, std::ostringstream &output); + + /** + * Called on creation of a new connection + */ + static void on_connection(uv_stream_t *server, int status); + + /** + * Call when data is written + */ + static void on_write(uv_write_t *req, int status); + + /** + * Called when data is read + */ + static void + on_read(uv_stream_t *client, ssize_t nread, const uv_buf_t *buf); + + /** + * Called to allocate buffer space for data to be read + */ + static void + on_alloc_buffer(uv_handle_t *handle, size_t size, uv_buf_t *buf); + + /** + * Called to cleanup the thread and socket during destruction + */ + static void on_cleanup(uv_async_t *handle); + + /** + * Async handle so we can wakeup the loop + */ + uv_async_t mAsync; + + /** + * The libuv loop + */ + uv_loop_t mServerLoop; + + /** + * The libuv thread context in which we run the loop + */ + uv_thread_t mServerThread; + + /** + * The inspect unix domain socket name, from the config file + */ + std::string mSockName; + + /** + * VPP inspect object to handle data read from the socket + */ + VOM::inspect mInspect; +}; +}; + +/* + * Local Variables: + * eval: (c-set-style "llvm.org") + * End: + */ + +#endif |