├── .clang-format ├── .gitignore ├── .gitmodules ├── AUTHORS ├── AUTHORS.md ├── LICENSE ├── Makefile.am ├── README ├── README.md ├── autogen.sh ├── configure.ac ├── debian ├── bgpview-docs.docs ├── bgpview2-tools.install ├── changelog ├── compat ├── control ├── copyright ├── libbgpview2-dev.install ├── libbgpview2.install ├── rules └── source │ └── format ├── lib ├── Makefile.am ├── bgpview.c ├── bgpview.h ├── bgpview_debug.c ├── bgpview_debug.h ├── consumers │ ├── Makefile.am │ ├── bgpview_consumer_interface.h │ ├── bgpview_consumer_manager.c │ ├── bgpview_consumer_manager.h │ ├── bgpview_consumer_utils.c │ ├── bgpview_consumer_utils.h │ ├── bvc_announcedpfxs.c │ ├── bvc_announcedpfxs.h │ ├── bvc_archiver.c │ ├── bvc_archiver.h │ ├── bvc_edges.c │ ├── bvc_edges.h │ ├── bvc_moas.c │ ├── bvc_moas.h │ ├── bvc_myviewprocess.c │ ├── bvc_myviewprocess.h │ ├── bvc_pathchange.c │ ├── bvc_pathchange.h │ ├── bvc_peerpfxorigins.c │ ├── bvc_peerpfxorigins.h │ ├── bvc_perasvisibility.c │ ├── bvc_perasvisibility.h │ ├── bvc_perfmonitor.c │ ├── bvc_perfmonitor.h │ ├── bvc_pergeovisibility.c │ ├── bvc_pergeovisibility.h │ ├── bvc_pfx2as.c │ ├── bvc_pfx2as.h │ ├── bvc_pfxorigins.c │ ├── bvc_pfxorigins.h │ ├── bvc_routedspace.c │ ├── bvc_routedspace.h │ ├── bvc_subpfx.c │ ├── bvc_subpfx.h │ ├── bvc_test.c │ ├── bvc_test.h │ ├── bvc_triplets.c │ ├── bvc_triplets.h │ ├── bvc_viewsender.c │ ├── bvc_viewsender.h │ ├── bvc_visibility.c │ └── bvc_visibility.h └── io │ ├── Makefile.am │ ├── bgpview_io.c │ ├── bgpview_io.h │ ├── bsrt │ ├── Makefile.am │ ├── bgpview_io_bsrt.c │ ├── bgpview_io_bsrt.h │ ├── bgpview_io_bsrt_int.h │ └── libbgpcorsaro │ │ ├── Makefile.am │ │ ├── bgpcorsaro.c │ │ ├── bgpcorsaro.h │ │ ├── bgpcorsaro_int.h │ │ ├── bgpcorsaro_io.c │ │ ├── bgpcorsaro_io.h │ │ ├── bgpcorsaro_log.c │ │ ├── bgpcorsaro_log.h │ │ ├── bgpcorsaro_plugin.h │ │ └── plugins │ │ ├── Makefile.am │ │ ├── bgpcorsaro_routingtables.c │ │ ├── bgpcorsaro_routingtables.h │ │ └── libroutingtables │ │ ├── Makefile.am │ │ ├── README.md │ │ ├── routingtables.c │ │ ├── routingtables.h │ │ ├── routingtables_int.h │ │ └── routingtables_metrics.c │ ├── file │ ├── Makefile.am │ ├── bgpview_io_file.c │ └── bgpview_io_file.h │ ├── kafka │ ├── Makefile.am │ ├── bgpview_io_kafka.c │ ├── bgpview_io_kafka.h │ ├── bgpview_io_kafka_consumer.c │ ├── bgpview_io_kafka_int.h │ └── bgpview_io_kafka_producer.c │ ├── test │ ├── Makefile.am │ ├── bgpview_io_test.c │ └── bgpview_io_test.h │ └── zmq │ ├── Makefile.am │ ├── bgpview_io_zmq.c │ ├── bgpview_io_zmq.h │ ├── bgpview_io_zmq_client.c │ ├── bgpview_io_zmq_client.h │ ├── bgpview_io_zmq_client_broker.c │ ├── bgpview_io_zmq_client_broker.h │ ├── bgpview_io_zmq_client_int.h │ ├── bgpview_io_zmq_int.h │ ├── bgpview_io_zmq_server.c │ ├── bgpview_io_zmq_server.h │ ├── bgpview_io_zmq_server_int.h │ ├── bgpview_io_zmq_store.c │ └── bgpview_io_zmq_store.h ├── m4 ├── ax_pthread.m4 ├── bs_with_io_mod.m4 └── disable-rpath.m4 └── tools ├── Makefile.am ├── consumers ├── Makefile.am └── bgpview-consumer.c └── io ├── Makefile.am ├── bgpview-server-zmq.c └── bvcat.c /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | Language: Cpp 3 | # BasedOnStyle: LLVM 4 | AccessModifierOffset: -2 5 | AlignAfterOpenBracket: Align 6 | AlignConsecutiveAssignments: false 7 | AlignConsecutiveDeclarations: false 8 | AlignEscapedNewlinesLeft: false 9 | AlignOperands: true 10 | AlignTrailingComments: true 11 | AllowAllParametersOfDeclarationOnNextLine: true 12 | AllowShortBlocksOnASingleLine: false 13 | AllowShortCaseLabelsOnASingleLine: false 14 | AllowShortFunctionsOnASingleLine: None 15 | AllowShortIfStatementsOnASingleLine: false 16 | AllowShortLoopsOnASingleLine: false 17 | AlwaysBreakAfterDefinitionReturnType: None 18 | AlwaysBreakAfterReturnType: None 19 | AlwaysBreakBeforeMultilineStrings: false 20 | AlwaysBreakTemplateDeclarations: false 21 | BinPackArguments: true 22 | BinPackParameters: true 23 | BraceWrapping: 24 | AfterClass: false 25 | AfterControlStatement: false 26 | AfterEnum: false 27 | AfterFunction: true 28 | AfterNamespace: false 29 | AfterObjCDeclaration: false 30 | AfterStruct: false 31 | AfterUnion: false 32 | BeforeCatch: false 33 | BeforeElse: false 34 | IndentBraces: false 35 | BreakBeforeBinaryOperators: None 36 | BreakBeforeBraces: Linux 37 | BreakBeforeTernaryOperators: true 38 | BreakConstructorInitializersBeforeComma: false 39 | BreakAfterJavaFieldAnnotations: false 40 | BreakStringLiterals: true 41 | ColumnLimit: 80 42 | CommentPragmas: '^ IWYU pragma:' 43 | ConstructorInitializerAllOnOneLineOrOnePerLine: false 44 | ConstructorInitializerIndentWidth: 4 45 | ContinuationIndentWidth: 2 46 | Cpp11BracedListStyle: true 47 | DerivePointerAlignment: false 48 | DisableFormat: false 49 | ExperimentalAutoDetectBinPacking: false 50 | ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] 51 | IncludeCategories: 52 | - Regex: '^".+_int' 53 | Priority: 1 54 | - Regex: '^"(bgpview|bvc)' 55 | Priority: 2 56 | - Regex: '^"config' 57 | Priority: 3 58 | - Regex: '^(<|")(utils|wandio_util|khash)' 59 | Priority: 4 60 | - Regex: '^"' 61 | Priority: 5 62 | - Regex: '^<' 63 | Priority: 6 64 | IndentCaseLabels: false 65 | IndentWidth: 2 66 | IndentWrappedFunctionNames: false 67 | KeepEmptyLinesAtTheStartOfBlocks: true 68 | MacroBlockBegin: '' 69 | MacroBlockEnd: '' 70 | MaxEmptyLinesToKeep: 1 71 | NamespaceIndentation: None 72 | ObjCBlockIndentWidth: 2 73 | ObjCSpaceAfterProperty: false 74 | ObjCSpaceBeforeProtocolList: true 75 | PenaltyBreakBeforeFirstCallParameter: 19 76 | PenaltyBreakComment: 300 77 | PenaltyBreakFirstLessLess: 120 78 | PenaltyBreakString: 1000 79 | PenaltyExcessCharacter: 1000000 80 | PenaltyReturnTypeOnItsOwnLine: 60 81 | PointerAlignment: Right 82 | ReflowComments: true 83 | SortIncludes: true 84 | SpaceAfterCStyleCast: false 85 | SpaceBeforeAssignmentOperators: true 86 | SpaceBeforeParens: ControlStatements 87 | SpaceInEmptyParentheses: false 88 | SpacesBeforeTrailingComments: 1 89 | SpacesInAngles: false 90 | SpacesInContainerLiterals: true 91 | SpacesInCStyleCastParentheses: false 92 | SpacesInParentheses: false 93 | SpacesInSquareBrackets: false 94 | Standard: Auto 95 | TabWidth: 8 96 | UseTab: Never 97 | JavaScriptQuotes: Leave 98 | ... 99 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # temp files 2 | *~ 3 | *.#* 4 | .DS_Store 5 | 6 | # Compiled Object files 7 | *.slo 8 | *.lo 9 | *.o 10 | 11 | # Compiled Dynamic libraries 12 | *.so 13 | 14 | # Compiled Static libraries 15 | *.lai 16 | *.la 17 | *.a 18 | *.pyc 19 | # helpful to me only? 20 | TAGS 21 | 22 | # Compiled programs 23 | *.tar.gz 24 | tools/consumers/bgpview-consumer 25 | tools/io/bgpview-server-zmq 26 | tools/io/bvcat 27 | 28 | # Test results 29 | test/*.log 30 | 31 | # Autotools files 32 | # http://www.gnu.org/software/automake 33 | 34 | Makefile.in 35 | Makefile 36 | 37 | # http://www.gnu.org/software/autoconf 38 | /autom4te.cache 39 | /aclocal.m4 40 | /compile 41 | /configure 42 | /depcomp 43 | /install-sh 44 | /missing 45 | .deps/ 46 | /config.h 47 | config.status 48 | config.h.in 49 | config.log 50 | configure.scan 51 | INSTALL 52 | stamp-h1 53 | .libs/ 54 | autoscan.log 55 | config.guess 56 | config.sub 57 | libtool 58 | ltmain.sh 59 | m4/libtool.m4 60 | m4/ltoptions.m4 61 | m4/ltsugar.m4 62 | m4/ltversion.m4 63 | m4/lt~obsolete.m4 64 | test/*.trs 65 | test-driver 66 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "common"] 2 | path = common 3 | url = https://github.com/caida/cc-common.git 4 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | AUTHORS.md -------------------------------------------------------------------------------- /AUTHORS.md: -------------------------------------------------------------------------------- 1 | BGPView Contributors 2 | -------------------- 3 | 4 | BGPView is primarily developed and 5 | maintained by as part of the [BGPStream](https://bgpstream.caida.org) 6 | project at the [Center for Applied Internet Data Analysis (CAIDA)](https://www.caida.org) 7 | at UC San Diego. 8 | 9 | BGPStream project members are: 10 | - Alistair King - Lead architect and developer 11 | - Alberto Dainotti - Project leader 12 | - Ken Keys - Developer 13 | - Mingwei Zhang - Developer 14 | 15 | The following is a list of people (in no particular order) who have made code 16 | contributions to BGPView: 17 | - Chiara Orsini 18 | - Danilo Giordano 19 | - Ruwaifa Anwar 20 | 21 | (If you feel that your name belongs on this list, please contact 22 | bgpstream-info@caida.org) 23 | 24 | See the [GitHub Contributors 25 | page](https://github.com/CAIDA/bgpview/graphs/contributors) for more 26 | detail. 27 | 28 | This file and the "Authors" section in file headers acknowledges contributors 29 | and does not imply legal ownership. Please see copyright notices in file headers 30 | for ownership information. 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2014 The Regents of the University of California. 2 | 3 | Redistribution and use in source and binary forms, with or without modification, 4 | are permitted provided that the following conditions are met: 5 | 6 | 1. Redistributions of source code must retain the above copyright notice, this 7 | list of conditions and the following disclaimer. 8 | 9 | 2. Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | 13 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 14 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 16 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 17 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 18 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 19 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 22 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2014 The Regents of the University of California. 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions are met: 6 | # 7 | # 1. Redistributions of source code must retain the above copyright notice, 8 | # this list of conditions and the following disclaimer. 9 | # 10 | # 2. Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | # POSSIBILITY OF SUCH DAMAGE. 25 | # 26 | 27 | SUBDIRS = common lib tools 28 | AM_CPPFLAGS = -I$(top_srcdir) \ 29 | -I$(top_srcdir)/common \ 30 | -I$(top_srcdir)/lib 31 | 32 | EXTRA_DIST = 33 | 34 | ACLOCAL_AMFLAGS = -I m4 35 | 36 | CLEANFILES = *~ 37 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | README.md -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (C) 2014 The Regents of the University of California. 4 | # 5 | # Redistribution and use in source and binary forms, with or without 6 | # modification, are permitted provided that the following conditions are met: 7 | # 8 | # 1. Redistributions of source code must retain the above copyright notice, 9 | # this list of conditions and the following disclaimer. 10 | # 11 | # 2. Redistributions in binary form must reproduce the above copyright notice, 12 | # this list of conditions and the following disclaimer in the documentation 13 | # and/or other materials provided with the distribution. 14 | # 15 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 19 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | # POSSIBILITY OF SUCH DAMAGE. 26 | # 27 | 28 | echo "Initializing submodules" 29 | git submodule init 30 | git submodule update 31 | echo "Running autoconf" 32 | autoreconf -vfi 33 | 34 | 35 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2014 The Regents of the University of California. 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions are met: 6 | # 7 | # 1. Redistributions of source code must retain the above copyright notice, 8 | # this list of conditions and the following disclaimer. 9 | # 10 | # 2. Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | # POSSIBILITY OF SUCH DAMAGE. 25 | # 26 | 27 | AC_PREREQ([2.68]) 28 | 29 | AC_INIT([bgpview], [2.0.0], [bgpstream-info@caida.org]) 30 | AM_INIT_AUTOMAKE([foreign]) 31 | 32 | BGPVIEW_MAJOR_VERSION=2 33 | BGPVIEW_MID_VERSION=0 34 | BGPVIEW_MINOR_VERSION=0 35 | 36 | LIBBGPVIEW_MAJOR_VERSION=2 37 | LIBBGPVIEW_MID_VERSION=0 38 | LIBBGPVIEW_MINOR_VERSION=0 39 | 40 | AC_DEFINE_UNQUOTED([BGPVIEW_MAJOR_VERSION],$BGPVIEW_MAJOR_VERSION, 41 | [bgpview major version]) 42 | AC_DEFINE_UNQUOTED([BGPVIEW_MID_VERSION],$BGPVIEW_MID_VERSION, 43 | [bgpview mid version]) 44 | AC_DEFINE_UNQUOTED([BGPVIEW_MINOR_VERSION],$BGPVIEW_MINOR_VERSION, 45 | [bgpview minor version]) 46 | 47 | AC_SUBST([BGPVIEW_MAJOR_VERSION]) 48 | AC_SUBST([BGPVIEW_MID_VERSION]) 49 | AC_SUBST([BGPVIEW_MINOR_VERSION]) 50 | 51 | AC_DEFINE_UNQUOTED([LIBBGPVIEW_MAJOR_VERSION],$LIBBGPVIEW_MAJOR_VERSION, 52 | [libbgpview major version]) 53 | AC_DEFINE_UNQUOTED([LIBBGPVIEW_MID_VERSION],$LIBBGPVIEW_MID_VERSION, 54 | [libbgpview mid version]) 55 | AC_DEFINE_UNQUOTED([LIBBGPVIEW_MINOR_VERSION],$LIBBGPVIEW_MINOR_VERSION, 56 | [libbgpview minor version]) 57 | 58 | AC_SUBST([LIBBGPVIEW_MAJOR_VERSION]) 59 | AC_SUBST([LIBBGPVIEW_MID_VERSION]) 60 | AC_SUBST([LIBBGPVIEW_MINOR_VERSION]) 61 | 62 | LT_INIT 63 | 64 | # Check if we should disable rpath. 65 | # 66 | # For advanced users: In certain configurations (e.g. when one of Bgpview's 67 | # dependencies is located in a directory which also holds an old 68 | # libbgpview.so), the rpath attributes added by libtool cause problems with 69 | # make check (or indeed with any non-installed binaries) as rpath will be 70 | # preferred over LD_LIBRARY_PATH. This does not seem to be a problem with 71 | # clang. When using --disable-rpath you will likely need to set LD_LIBRARY_PATH 72 | # if you are using libraries in non-system locations. YMMV. 73 | # 74 | DISABLE_RPATH 75 | 76 | AM_INIT_AUTOMAKE 77 | 78 | AC_CONFIG_MACRO_DIR([m4]) 79 | 80 | AC_CONFIG_SRCDIR([lib/bgpview.c]) 81 | AC_CONFIG_HEADERS([config.h]) 82 | 83 | # Checks for programs. 84 | AC_PROG_LIBTOOL 85 | AC_PROG_CXX 86 | AM_PROG_LIBTOOL 87 | AC_PROG_CC_C99 # C99 is required because of bool 88 | 89 | AC_SYS_LARGEFILE 90 | 91 | AH_VERBATIM([_GNU_SOURCE], 92 | [/* Enable GNU extensions on systems that have them. */ 93 | #ifndef _GNU_SOURCE 94 | #define _GNU_SOURCE 95 | #endif]) 96 | 97 | AC_CHECK_FUNCS([gettimeofday memset strdup strstr strsep strlcpy vasprintf]) 98 | 99 | # should we dump debug output to stderr and not optmize the build? 100 | 101 | AC_MSG_CHECKING([whether to build with debug information]) 102 | AC_ARG_ENABLE([debug], 103 | [AS_HELP_STRING([--enable-debug], 104 | [enable debug data generation (def=no)])], 105 | [debugit="$enableval"], 106 | [debugit=no]) 107 | AC_MSG_RESULT([$debugit]) 108 | 109 | if test x"$debugit" = x"yes"; then 110 | AC_DEFINE([DEBUG],[],[Debug Mode]) 111 | fi 112 | 113 | # Checks for typedefs, structures, and compiler characteristics. 114 | AC_TYPE_SIZE_T 115 | AC_TYPE_UINT16_T 116 | AC_TYPE_UINT32_T 117 | AC_TYPE_UINT64_T 118 | AC_TYPE_UINT8_T 119 | 120 | # Checks for library functions. 121 | AC_FUNC_MALLOC 122 | AC_FUNC_REALLOC 123 | 124 | # Checks for header files. 125 | AC_CHECK_HEADERS([arpa/inet.h inttypes.h limits.h math.h stdlib.h string.h \ 126 | time.h sys/time.h]) 127 | 128 | # Checks for mandatory libraries 129 | 130 | # this code is needed to get the right threading library on a mac 131 | STASH_CFLAGS="$CFLAGS" 132 | CFLAGS= 133 | AX_PTHREAD(, [AC_MSG_ERROR([pthreads required])]) 134 | CFLAGS="$STASH_CFLAGS" 135 | LIBS="$PTHREAD_LIBS $LIBS" 136 | CFLAGS="$CFLAGS $PTHREAD_CFLAGS" 137 | CC="$PTHREAD_CC" 138 | 139 | # Check that BGPStream is installed 140 | AC_CHECK_LIB([bgpstream], [bgpstream_create], , 141 | [AC_MSG_ERROR( [libbgpstream is required (https://bgpstream.caida.org)])]) 142 | AC_CHECK_LIB([m], [log2], , 143 | [AC_MSG_ERROR( [libm is required])]) 144 | 145 | 146 | # CONSUMERS 147 | # TODO: move consumers into separate repos (IODA and BGP-Hijacks) 148 | # TODO: Make BGPView Consumers optional 149 | AC_MSG_NOTICE([checking BGPView Consumer dependencies]) 150 | 151 | AC_CHECK_LIB([timeseries], [timeseries_init], , [ 152 | AC_MSG_ERROR([libtimeseries is required for the Per-AS Visibility plugin]) 153 | ]) 154 | AC_CHECK_LIB([ipmeta], [ipmeta_lookup_pfx], ,[AC_MSG_ERROR([ipmeta v3 is required])]) 155 | 156 | # BGPView IO modules 157 | # TODO: Make BGPView-IO optional (one may just want the datastructure without IO/Consumers) 158 | AC_MSG_NOTICE([configuring BGPView IO modules]) 159 | 160 | # Test module 161 | BS_WITH_IO_MOD([test],[TEST],[yes]) 162 | 163 | # File module 164 | BS_WITH_IO_MOD([file],[FILE],[yes]) 165 | 166 | # BGPStream RoutingTable module 167 | BS_WITH_IO_MOD([bsrt],[BSRT],[yes]) 168 | 169 | # ZMQ module 170 | BS_WITH_IO_MOD([zmq],[ZMQ],[no]) 171 | 172 | # Kafka module 173 | BS_WITH_IO_MOD([kafka],[KAFKA],[yes]) 174 | 175 | # BGPView IO dependencies 176 | AC_MSG_NOTICE([checking BGPView IO module dependencies]) 177 | 178 | if test "x$with_io_file" = xyes; then 179 | AC_SEARCH_LIBS([wandio_create], [wandio], [with_wandio=yes], 180 | [AC_MSG_ERROR( 181 | [libwandio required (http://research.wand.net.nz/software/libwandio.php) 182 | for the file IO module] 183 | )]) 184 | fi 185 | AM_CONDITIONAL([WITH_WANDIO], [test "x$with_wandio" = xyes]) 186 | 187 | if test "x$with_io_zmq" = xyes; then 188 | AC_CHECK_LIB([czmq], [zctx_new], ,[AC_MSG_ERROR( 189 | [CZMQ is required for the ZMQ IO module])]) 190 | fi 191 | 192 | if test "x$with_io_kafka" = xyes; then 193 | # check for kafka 194 | AC_CHECK_LIB([rdkafka], [rd_kafka_query_watermark_offsets], , 195 | [AC_MSG_ERROR( [librdkafka required for the Kafka IO module])]) 196 | fi 197 | 198 | AC_HEADER_ASSERT 199 | 200 | AC_CONFIG_FILES([Makefile 201 | lib/Makefile 202 | lib/consumers/Makefile 203 | lib/io/Makefile 204 | lib/io/file/Makefile 205 | lib/io/kafka/Makefile 206 | lib/io/bsrt/Makefile 207 | lib/io/bsrt/libbgpcorsaro/Makefile 208 | lib/io/bsrt/libbgpcorsaro/plugins/Makefile 209 | lib/io/bsrt/libbgpcorsaro/plugins/libroutingtables/Makefile 210 | lib/io/test/Makefile 211 | lib/io/zmq/Makefile 212 | tools/Makefile 213 | tools/io/Makefile 214 | tools/consumers/Makefile 215 | common/Makefile 216 | common/libpatricia/Makefile 217 | common/libinterval3/Makefile 218 | common/libinterval3/rb_tree/Makefile 219 | common/libcsv/Makefile 220 | common/libjsmn/Makefile]) 221 | AC_OUTPUT 222 | -------------------------------------------------------------------------------- /debian/bgpview-docs.docs: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /debian/bgpview2-tools.install: -------------------------------------------------------------------------------- 1 | usr/bin/bgpview-consumer 2 | usr/bin/bvcat 3 | -------------------------------------------------------------------------------- /debian/changelog: -------------------------------------------------------------------------------- 1 | libbgpview2 (2.0.0~rc3) unstable; urgency=medium 2 | 3 | * Fix bad prefix bug in pergeo_visibility v6 code 4 | 5 | -- Shane Alcock Thu, 19 Aug 2021 08:37:26 +1200 6 | 7 | libbgpview2 (2.0.0~rc2) unstable; urgency=medium 8 | 9 | * Add IPv6 support to the pergeo_visibility consumer (by Shane Alcock @salcock) 10 | 11 | -- Mingwei Zhang Thu, 22 Jan 2021 00:00:00 +0000 12 | 13 | libbgpview2 (2.0.0~rc1-1) unstable; urgency=medium 14 | 15 | * Bug fix for debian package dependencies 16 | 17 | -- Alistair King Wed, 05 Aug 2020 20:03:16 +0000 18 | 19 | libbgpview2 (2.0.0~rc1) unstable; urgency=medium 20 | 21 | * This is the first release candidate for libbgpview version 2.0.0 22 | 23 | -- Alistair King Tue, 04 Aug 2020 21:07:36 +0000 24 | 25 | -------------------------------------------------------------------------------- /debian/compat: -------------------------------------------------------------------------------- 1 | 10 2 | -------------------------------------------------------------------------------- /debian/control: -------------------------------------------------------------------------------- 1 | Source: libbgpview2 2 | Section: libs 3 | Priority: optional 4 | Maintainer: CAIDA Software Maintainer 5 | Build-Depends: debhelper (>= 10), autotools-dev, libbgpstream2-dev (>=2.0.0~rc5), 6 | libtimeseries0-dev (>=1.0.0), libipmeta2-dev (>=3.0.0), 7 | libwandio1-dev (>=4.2.0), librdkafka-dev (>=0.11.3) 8 | Standards-Version: 4.1.2 9 | Homepage: https://github.com/CAIDA/bgpview 10 | 11 | Package: bgpview 12 | Architecture: any 13 | Section: libdevel 14 | Depends: bgpview2-tools (=${binary:Version}), 15 | libbgpview2-dev (=${binary:Version}), ${misc:Depends} 16 | Description: Meta package for full BGPView install 17 | Meta package for latest libbgpview library, development environment, and 18 | command-line tools. 19 | . 20 | BGPStream: An open-source software framework for live and historical BGP data 21 | analysis, supporting scientific research, operational monitoring, and 22 | post-event analysis. 23 | 24 | Package: bgpview2-tools 25 | Architecture: any 26 | Section: libs 27 | Depends: libbgpview2 (=${binary:Version}), ${shlibs:Depends}, ${misc:Depends} 28 | Description: BGPView tools 29 | Command-line tools for obtaining and processing BGP data using BGPView 30 | . 31 | BGPStream: An open-source software framework for live and historical BGP data 32 | analysis, supporting scientific research, operational monitoring, and 33 | post-event analysis. 34 | 35 | Package: libbgpview2 36 | Architecture: any 37 | Section: libs 38 | Depends: libbgpstream2 (>=2.0.0~rc5), libtimeseries0 (>=1.0.0), 39 | libipmeta2 (>=3.0.0), libwandio1 (>=4.2.0), librdkafka1 (>=0.11.3), 40 | ${shlibs:Depends}, ${misc:Depends} 41 | Description: Software framework for live and historical BGP data analysis 42 | BGPStream: An open-source software framework for live and historical BGP data 43 | analysis, supporting scientific research, operational monitoring, and 44 | post-event analysis. 45 | 46 | Package: libbgpview2-dev 47 | Architecture: any 48 | Section: libdevel 49 | Depends: libbgpview2 (=${binary:Version}), ${misc:Depends} 50 | Description: Development environment for libbgpview2 51 | Development headers and shared libraries for the libbgpview2 library. 52 | . 53 | BGPStream: An open-source software framework for live and historical BGP data 54 | analysis, supporting scientific research, operational monitoring, and 55 | post-event analysis. 56 | -------------------------------------------------------------------------------- /debian/copyright: -------------------------------------------------------------------------------- 1 | Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ 2 | Upstream-Name: BGPView 3 | Source: https://github.com/CAIDA/bgpview 4 | 5 | Files: * 6 | Copyright: 2014 The Regents of the University of California. 7 | License: BSD-2-Clause 8 | Redistribution and use in source and binary forms, with or without modification, 9 | are permitted provided that the following conditions are met: 10 | . 11 | 1. Redistributions of source code must retain the above copyright notice, this 12 | list of conditions and the following disclaimer. 13 | . 14 | 2. Redistributions in binary form must reproduce the above copyright notice, 15 | this list of conditions and the following disclaimer in the documentation 16 | and/or other materials provided with the distribution. 17 | . 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /debian/libbgpview2-dev.install: -------------------------------------------------------------------------------- 1 | usr/include/bgpview*.h 2 | usr/lib/*/*.so 3 | -------------------------------------------------------------------------------- /debian/libbgpview2.install: -------------------------------------------------------------------------------- 1 | usr/lib/x86_64-linux-gnu/*.so.* 2 | usr/lib/x86_64-linux-gnu/*.a 3 | -------------------------------------------------------------------------------- /debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | 3 | # Uncomment this to turn on verbose mode. 4 | #export DH_VERBOSE=1 5 | 6 | # Enable all hardening features, since traces are untrusted input. 7 | export DEB_BUILD_MAINT_OPTIONS = hardening=+all 8 | DPKG_EXPORT_BUILDFLAGS = 1 9 | include /usr/share/dpkg/buildflags.mk 10 | 11 | DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH) 12 | 13 | # These are used for cross-compiling and for saving the configure script 14 | # from having to guess our platform (since we know it already) 15 | DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE) 16 | DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE) 17 | CONFFLAGS = 18 | ifeq ($(DEB_BUILD_GNU_TYPE), $(DEB_HOST_GNU_TYPE)) 19 | CONFFLAGS += --build $(DEB_HOST_GNU_TYPE) 20 | else 21 | CONFFLAGS += --build $(DEB_BUILD_GNU_TYPE) --host $(DEB_HOST_GNU_TYPE) 22 | endif 23 | 24 | 25 | configure: 26 | 27 | configure-stamp: configure 28 | dh_testdir 29 | 30 | dh_autoreconf 31 | 32 | ./configure $(CONFFLAGS) \ 33 | --prefix=/usr \ 34 | --mandir=\$${prefix}/share/man \ 35 | --infodir=\$${prefix}/share/info \ 36 | --libdir=\$${prefix}/lib/${DEB_HOST_MULTIARCH} 37 | 38 | touch configure-stamp 39 | 40 | build: build-arch build-indep 41 | build-arch: build-stamp 42 | build-indep: build-stamp 43 | build-stamp: configure-stamp 44 | dh_testdir 45 | 46 | # Add here commands to compile the package. 47 | $(MAKE) 48 | 49 | touch build-stamp 50 | 51 | clean: 52 | dh_testdir 53 | dh_testroot 54 | rm -f build-stamp configure-stamp 55 | 56 | [ ! -f Makefile ] || $(MAKE) clean 57 | [ ! -f Makefile ] || $(MAKE) distclean 58 | 59 | dh_autoreconf_clean 60 | dh_clean 61 | 62 | install: build 63 | dh_testdir 64 | dh_testroot 65 | dh_clean -k 66 | dh_installdirs 67 | 68 | # Add here commands to install the package into debian/tmp 69 | $(MAKE) install DESTDIR=$(CURDIR)/debian/tmp 70 | 71 | 72 | # Build architecture-independent files here. 73 | binary-indep: build install 74 | # We have nothing to do by default. 75 | 76 | # Build architecture-dependent files here. 77 | binary-arch: build install 78 | dh_testdir 79 | dh_testroot 80 | #dh_installchangelogs ChangeLog 81 | dh_installchangelogs 82 | dh_installdocs 83 | dh_installexamples 84 | dh_installman 85 | dh_install --sourcedir=debian/tmp 86 | dh_link 87 | dh_strip 88 | dh_compress 89 | dh_fixperms 90 | dh_makeshlibs 91 | dh_installdeb 92 | dh_shlibdeps --dpkg-shlibdeps-params=--ignore-missing-info 93 | dh_gencontrol 94 | dh_md5sums 95 | dh_builddeb 96 | 97 | binary: binary-indep binary-arch 98 | .PHONY: build clean binary-indep binary-arch binary install 99 | -------------------------------------------------------------------------------- /debian/source/format: -------------------------------------------------------------------------------- 1 | 3.0 (quilt) 2 | -------------------------------------------------------------------------------- /lib/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2014 The Regents of the University of California. 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions are met: 6 | # 7 | # 1. Redistributions of source code must retain the above copyright notice, 8 | # this list of conditions and the following disclaimer. 9 | # 10 | # 2. Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | # POSSIBILITY OF SUCH DAMAGE. 25 | # 26 | 27 | SUBDIRS = io consumers 28 | 29 | AM_CPPFLAGS = -I$(top_srcdir) \ 30 | -I$(top_srcdir)/common \ 31 | -I$(top_srcdir)/lib/consumers \ 32 | -I$(top_srcdir)/lib/io 33 | 34 | lib_LTLIBRARIES = libbgpview.la 35 | 36 | include_HEADERS = \ 37 | bgpview.h 38 | 39 | libbgpview_la_SOURCES = \ 40 | bgpview.h \ 41 | bgpview.c \ 42 | bgpview_debug.c \ 43 | bgpview_debug.h 44 | 45 | libbgpview_la_LIBADD = \ 46 | $(top_builddir)/common/libcccommon.la \ 47 | $(top_builddir)/lib/io/libbgpview_io.la \ 48 | $(top_builddir)/lib/consumers/libbgpview_consumers.la 49 | 50 | libbgpview_la_LDFLAGS = -version-info @LIBBGPVIEW_MAJOR_VERSION@:@LIBBGPVIEW_MID_VERSION@:@LIBBGPVIEW_MINOR_VERSION@ 51 | 52 | ACLOCAL_AMFLAGS = -I m4 53 | 54 | CLEANFILES = *~ 55 | -------------------------------------------------------------------------------- /lib/bgpview_debug.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | #include "bgpview.h" 27 | #include "bgpview_debug.h" 28 | #include "config.h" 29 | #include 30 | #include 31 | #include 32 | 33 | static void peers_dump(bgpview_t *view, bgpview_iter_t *it) 34 | { 35 | bgpstream_peer_id_t peerid; 36 | bgpstream_peer_sig_t *ps; 37 | int v4pfx_cnt = -1; 38 | int v6pfx_cnt = -1; 39 | char peer_str[INET6_ADDRSTRLEN] = ""; 40 | 41 | fprintf(stdout, "Peers (%d):\n", 42 | bgpview_peer_cnt(view, BGPVIEW_FIELD_ACTIVE)); 43 | 44 | for (bgpview_iter_first_peer(it, BGPVIEW_FIELD_ACTIVE); 45 | bgpview_iter_has_more_peer(it); bgpview_iter_next_peer(it)) { 46 | peerid = bgpview_iter_peer_get_peer_id(it); 47 | ps = bgpview_iter_peer_get_sig(it); 48 | assert(ps); 49 | v4pfx_cnt = bgpview_iter_peer_get_pfx_cnt(it, BGPSTREAM_ADDR_VERSION_IPV4, 50 | BGPVIEW_FIELD_ACTIVE); 51 | assert(v4pfx_cnt >= 0); 52 | v6pfx_cnt = bgpview_iter_peer_get_pfx_cnt(it, BGPSTREAM_ADDR_VERSION_IPV6, 53 | BGPVIEW_FIELD_ACTIVE); 54 | assert(v6pfx_cnt >= 0); 55 | 56 | bgpstream_addr_ntop(peer_str, INET6_ADDRSTRLEN, &ps->peer_ip_addr); 57 | 58 | fprintf(stdout, 59 | " %" PRIu16 ":\t%s, %s %" PRIu32 " (%d v4 pfxs, %d v6 pfxs)\n", 60 | peerid, ps->collector_str, peer_str, ps->peer_asnumber, v4pfx_cnt, 61 | v6pfx_cnt); 62 | } 63 | } 64 | 65 | static void pfxs_dump(bgpview_t *view, bgpview_iter_t *it) 66 | { 67 | bgpstream_pfx_t *pfx; 68 | char pfx_str[INET6_ADDRSTRLEN + 3] = ""; 69 | char path_str[4096] = ""; 70 | bgpstream_as_path_t *path = NULL; 71 | 72 | fprintf(stdout, "Prefixes (v4 %d, v6 %d):\n", 73 | bgpview_v4pfx_cnt(view, BGPVIEW_FIELD_ACTIVE), 74 | bgpview_v6pfx_cnt(view, BGPVIEW_FIELD_ACTIVE)); 75 | 76 | for (bgpview_iter_first_pfx(it, 0, BGPVIEW_FIELD_ACTIVE); 77 | bgpview_iter_has_more_pfx(it); bgpview_iter_next_pfx(it)) { 78 | pfx = bgpview_iter_pfx_get_pfx(it); 79 | bgpstream_pfx_snprintf(pfx_str, INET6_ADDRSTRLEN + 3, pfx); 80 | fprintf(stdout, " %s (%d peers)\n", pfx_str, 81 | bgpview_iter_pfx_get_peer_cnt(it, BGPVIEW_FIELD_ACTIVE)); 82 | 83 | for (bgpview_iter_pfx_first_peer(it, BGPVIEW_FIELD_ACTIVE); 84 | bgpview_iter_pfx_has_more_peer(it); bgpview_iter_pfx_next_peer(it)) { 85 | path = bgpview_iter_pfx_peer_get_as_path(it); 86 | bgpstream_as_path_snprintf(path_str, 4096, path); 87 | bgpstream_as_path_destroy(path); 88 | fprintf(stdout, " %" PRIu16 ":\t%s\n", 89 | bgpview_iter_peer_get_peer_id(it), path_str); 90 | } 91 | } 92 | } 93 | 94 | /* ========== PUBLIC FUNCTIONS ========== */ 95 | 96 | void bgpview_debug_dump(bgpview_t *view) 97 | { 98 | bgpview_iter_t *it = NULL; 99 | 100 | if (view == NULL) { 101 | fprintf(stdout, "------------------------------\n" 102 | "NULL\n" 103 | "------------------------------\n\n"); 104 | } else { 105 | it = bgpview_iter_create(view); 106 | assert(it); 107 | 108 | fprintf(stdout, "------------------------------\n" 109 | "Time:\t%" PRIu32 "\n" 110 | "Created:\t%ld\n", 111 | bgpview_get_time(view), (long)bgpview_get_time_created(view)); 112 | 113 | peers_dump(view, it); 114 | 115 | pfxs_dump(view, it); 116 | 117 | fprintf(stdout, "------------------------------\n\n"); 118 | 119 | bgpview_iter_destroy(it); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /lib/bgpview_debug.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef __BGPVIEW_DEBUG_H 28 | #define __BGPVIEW_DEBUG_H 29 | 30 | #include "bgpview.h" 31 | 32 | /** Dump the given BGP View to stdout 33 | * 34 | * @param view pointer to a view structure 35 | */ 36 | void bgpview_debug_dump(bgpview_t *view); 37 | 38 | #endif /* __BGPVIEW_DEBUG_H */ 39 | -------------------------------------------------------------------------------- /lib/consumers/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2014 The Regents of the University of California. 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions are met: 6 | # 7 | # 1. Redistributions of source code must retain the above copyright notice, 8 | # this list of conditions and the following disclaimer. 9 | # 10 | # 2. Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | # POSSIBILITY OF SUCH DAMAGE. 25 | # 26 | 27 | SUBDIRS = 28 | 29 | AM_CPPFLAGS = -I$(top_srcdir) \ 30 | -I$(top_srcdir)/common \ 31 | -I$(top_srcdir)/lib \ 32 | -I$(top_srcdir)/lib/io \ 33 | -I$(top_srcdir)/lib/consumers 34 | 35 | # BGPView IO is needed for bgpview_io_dump and bgpview_io_write 36 | 37 | noinst_LTLIBRARIES = libbgpview_consumers.la 38 | 39 | include_HEADERS = bgpview_consumer_manager.h 40 | 41 | CONSUMER_SRCS= 42 | CONSUMER_LIBS= 43 | 44 | # Test Consumer 45 | CONSUMER_SRCS += \ 46 | bvc_test.c \ 47 | bvc_test.h 48 | 49 | # Performance Monitor Consumer 50 | CONSUMER_SRCS += \ 51 | bvc_perfmonitor.c \ 52 | bvc_perfmonitor.h 53 | 54 | # Visibility Consumer 55 | CONSUMER_SRCS += \ 56 | bvc_visibility.c \ 57 | bvc_visibility.h 58 | 59 | # Per-AS Visibility Consumer (depends on Visibility) 60 | CONSUMER_SRCS += \ 61 | bvc_perasvisibility.c \ 62 | bvc_perasvisibility.h 63 | 64 | # Per-Geo Visibility Consumer (depends on Visibility) 65 | CONSUMER_SRCS += \ 66 | bvc_pergeovisibility.c \ 67 | bvc_pergeovisibility.h 68 | 69 | # Announced Prefixes Consumer (depends on Visibility) 70 | CONSUMER_SRCS += \ 71 | bvc_announcedpfxs.c \ 72 | bvc_announcedpfxs.h 73 | 74 | # Moas Consumer (depends on Visibility) 75 | CONSUMER_SRCS += \ 76 | bvc_moas.c \ 77 | bvc_moas.h 78 | 79 | if WITH_BGPVIEW_IO_FILE 80 | # Archiver consumer 81 | CONSUMER_SRCS += \ 82 | bvc_archiver.c \ 83 | bvc_archiver.h 84 | endif 85 | 86 | # Edges consumer 87 | CONSUMER_SRCS += \ 88 | bvc_edges.c \ 89 | bvc_edges.h 90 | 91 | # Triplets consumer 92 | CONSUMER_SRCS += \ 93 | bvc_triplets.c \ 94 | bvc_triplets.h 95 | 96 | # Pfxorigins consumer 97 | CONSUMER_SRCS += \ 98 | bvc_pfxorigins.c \ 99 | bvc_pfxorigins.h 100 | 101 | # Peerpfxorigins consumer 102 | CONSUMER_SRCS += \ 103 | bvc_peerpfxorigins.c \ 104 | bvc_peerpfxorigins.h 105 | 106 | # Routed Space Consumer (no dependencies) 107 | CONSUMER_SRCS += \ 108 | bvc_routedspace.c \ 109 | bvc_routedspace.h 110 | 111 | # My View Process Consumer (no dependencies) 112 | CONSUMER_SRCS += \ 113 | bvc_myviewprocess.c \ 114 | bvc_myviewprocess.h 115 | 116 | # Alistair can't figure out how to do an OR... 117 | if WITH_BGPVIEW_IO_KAFKA 118 | # view sender 119 | CONSUMER_SRCS += \ 120 | bvc_viewsender.c \ 121 | bvc_viewsender.h 122 | else 123 | if WITH_BGPVIEW_IO_ZMQ 124 | # view sender 125 | CONSUMER_SRCS += \ 126 | bvc_viewsender.c \ 127 | bvc_viewsender.h 128 | endif 129 | endif 130 | 131 | # Path Change (no dependencies) 132 | CONSUMER_SRCS += \ 133 | bvc_pathchange.c \ 134 | bvc_pathchange.h 135 | 136 | # Subpfx consumer 137 | CONSUMER_SRCS += \ 138 | bvc_subpfx.c \ 139 | bvc_subpfx.h 140 | 141 | # Prefix-to-AS consumer 142 | CONSUMER_SRCS += \ 143 | bvc_pfx2as.c \ 144 | bvc_pfx2as.h 145 | 146 | # -- sample how to add conditional consumer 147 | #if WITH_ 148 | #SUBDIRS += lib 149 | #AM_CPPFLAGS += -I$(top_srcdir)/lib/consumers/lib 150 | #CONSUMER_SRCS += \ 151 | # bvc_.c \ 152 | # bvc_.h 153 | #CONSUMER_LIBS += $(top_builddir)/lib/consumers/lib/lib.la 154 | #endif 155 | 156 | libbgpview_consumers_la_SOURCES = bgpview_consumer_manager.h \ 157 | bgpview_consumer_manager.c \ 158 | bgpview_consumer_utils.h \ 159 | bgpview_consumer_utils.c \ 160 | bgpview_consumer_interface.h \ 161 | $(CONSUMER_SRCS) 162 | 163 | libbgpview_consumers_la_LIBADD = $(CONSUMER_LIBS) 164 | 165 | ACLOCAL_AMFLAGS = -I m4 166 | 167 | CLEANFILES = *~ 168 | -------------------------------------------------------------------------------- /lib/consumers/bgpview_consumer_interface.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef __BGPVIEW_CONSUMER_INTERFACE_H 28 | #define __BGPVIEW_CONSUMER_INTERFACE_H 29 | 30 | #include "bgpview.h" 31 | #include "bgpview_consumer_manager.h" /* for bvc_t */ 32 | #include 33 | 34 | /** @file 35 | * 36 | * @brief Header file that exposes the protected interface of the bgpview 37 | * consumer API 38 | * 39 | * @author Alistair King 40 | * 41 | */ 42 | 43 | /** Convenience macro to allow consumer implementations to retrieve their state 44 | * object 45 | */ 46 | #define BVC_GET_STATE(consumer, type) \ 47 | ((bvc_##type##_state_t *)(consumer)->state) 48 | 49 | /** Convenience macro to allow consumer implementations to store a state 50 | pointer */ 51 | #define BVC_SET_STATE(consumer, ptr) \ 52 | do { \ 53 | (consumer)->state = ptr; \ 54 | } while (0) 55 | 56 | #define BVC_GET_TIMESERIES(consumer) ((consumer)->timeseries) 57 | 58 | #define BVC_GET_CHAIN_STATE(consumer) ((consumer)->chain_state) 59 | 60 | /** Convenience macro that defines all the function prototypes for the 61 | * timeseries 62 | * consumer API 63 | */ 64 | #define BVC_GENERATE_PROTOS(consname) \ 65 | bvc_t *bvc_##consname##_alloc(void); \ 66 | int bvc_##consname##_init(bvc_t *ds, int argc, char **argv); \ 67 | void bvc_##consname##_destroy(bvc_t *ds); \ 68 | int bvc_##consname##_process_view(bvc_t *ds, bgpview_t *view); 69 | 70 | /** Convenience macro that defines all the function pointers for the timeseries 71 | * consumer API 72 | */ 73 | #define BVC_GENERATE_PTRS(consname) \ 74 | bvc_##consname##_init, bvc_##consname##_destroy, \ 75 | bvc_##consname##_process_view, 0, NULL, NULL, NULL 76 | 77 | /** Structure which represents a metadata consumer */ 78 | struct bvc { 79 | /** 80 | * @name Consumer information fields 81 | * 82 | * These fields are always filled, even if a consumer is not enabled. 83 | * 84 | * @{ */ 85 | 86 | /** The ID of the consumer */ 87 | bvc_id_t id; 88 | 89 | /** The name of the consumer */ 90 | const char *name; 91 | 92 | /** }@ */ 93 | 94 | /** 95 | * @name Consumer function pointers 96 | * 97 | * These pointers are always filled, even if a consumer is not enabled. 98 | * Until the consumer is enabled, only the init function can be called. 99 | * 100 | * @{ */ 101 | 102 | /** Initialize and enable this consumer 103 | * 104 | * @param consumer The consumer object to allocate 105 | * @param argc The number of tokens in argv 106 | * @param argv An array of strings parsed from the command line 107 | * @return 0 if the consumer is successfully initialized, -1 otherwise 108 | * 109 | * @note the most common reason for returning -1 will likely be incorrect 110 | * command line arguments. 111 | * 112 | * @warning the strings contained in argv will be free'd once this function 113 | * returns. Ensure you make appropriate copies as needed. 114 | */ 115 | int (*init)(struct bvc *consumer, int argc, char **argv); 116 | 117 | /** Shutdown and free consumer-specific state for this consumer 118 | * 119 | * @param consumer The consumer object to free 120 | * 121 | * @note consumers should *only* free consumer-specific state. All other state 122 | * will be free'd for them by the consumer manager. 123 | */ 124 | void (*destroy)(struct bvc *consumer); 125 | 126 | /** Process a new BGPView table 127 | * 128 | * @param consumer The consumer object 129 | * @param view The view to process 130 | * @return 0 if the view was processed successfully, -1 otherwise. 131 | * 132 | * This is the core of the consumer API 133 | */ 134 | int (*process_view)(struct bvc *consumer, bgpview_t *view); 135 | 136 | /** }@ */ 137 | 138 | /** 139 | * @name Consumer state fields 140 | * 141 | * These fields are only set if the consumer is enabled (and initialized) 142 | * @note These fields should *not* be directly manipulated by 143 | * consumers. Instead they should use accessor functions provided by the 144 | * consumer manager. 145 | * 146 | * @{ */ 147 | 148 | int enabled; 149 | 150 | /** An opaque pointer to consumer-specific state if needed by the consumer */ 151 | void *state; 152 | 153 | /** A borrowed pointer to a configured and operational timeseries instance */ 154 | timeseries_t *timeseries; 155 | 156 | /** A borrowed pointer to the shared consumer state object */ 157 | bvc_chain_state_t *chain_state; 158 | 159 | /** }@ */ 160 | }; 161 | 162 | #endif /* __BGPVIEW_CONSUMER_INT_H */ 163 | -------------------------------------------------------------------------------- /lib/consumers/bgpview_consumer_utils.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include "utils.h" 37 | #include "bgpview.h" 38 | #include "bgpview_consumer_utils.h" 39 | 40 | iow_t* bvcu_open_outfile(char *namebuf, const char *fmt, ...) 41 | { 42 | iow_t *file; 43 | va_list ap; 44 | 45 | va_start(ap, fmt); 46 | int size = vsnprintf(namebuf, BVCU_PATH_MAX-1, fmt, ap); 47 | va_end(ap); 48 | if (size >= BVCU_PATH_MAX) { 49 | fprintf(stderr, "ERROR: File name too long\n"); 50 | return NULL; 51 | } 52 | if ((file = wandio_wcreate(namebuf, wandio_detect_compression_type(namebuf), 53 | BVCU_DEFAULT_COMPRESS_LEVEL, O_CREAT)) == NULL) { 54 | fprintf(stderr, "ERROR: Could not open %s for writing\n", namebuf); 55 | return NULL; 56 | } 57 | return file; 58 | } 59 | 60 | int bvcu_create_donefile(const char *filename) 61 | { 62 | char buf[BVCU_PATH_MAX]; 63 | FILE *file; 64 | if (snprintf(buf, BVCU_PATH_MAX, "%s.done", filename) >= BVCU_PATH_MAX) { 65 | fprintf(stderr, "ERROR: File name too long\n"); 66 | return -1; 67 | } 68 | if (!(file = fopen(buf, "w"))) { 69 | fprintf(stderr, "ERROR: could not create %s: %s\n", buf, strerror(errno)); 70 | return -1; 71 | } 72 | fclose(file); 73 | return 0; 74 | } 75 | 76 | int bvcu_is_writable_folder(const char *path) 77 | { 78 | struct stat st; 79 | errno = 0; 80 | if (stat(path, &st) == -1) { 81 | fprintf(stderr, "ERROR: %s: %s\n", path, strerror(errno)); 82 | return 0; 83 | } else if (!S_ISDIR(st.st_mode)) { 84 | errno = ENOTDIR; 85 | fprintf(stderr, "ERROR: %s: %s\n", path, strerror(errno)); 86 | return 0; 87 | } else if (access(path, W_OK) == -1) { 88 | fprintf(stderr, "ERROR: %s: %s\n", path, strerror(errno)); 89 | return 0; 90 | } 91 | 92 | return 1; 93 | } 94 | 95 | int bvcu_print_pfx_peer_as_path(iow_t *wf, bgpview_iter_t *it, 96 | const char *delim1, const char *delim2) 97 | { 98 | char asn_buffer[1024]; 99 | const char *delim = delim1; 100 | bgpstream_as_path_seg_t *seg; 101 | 102 | bgpview_iter_pfx_peer_as_path_seg_iter_reset(it); 103 | 104 | while ((seg = bgpview_iter_pfx_peer_as_path_seg_next(it))) { 105 | if (bgpstream_as_path_seg_snprintf(asn_buffer, sizeof(asn_buffer), seg) >= 106 | sizeof(asn_buffer)) { 107 | fprintf(stderr, "ERROR: ASN print truncated output\n"); 108 | return -1; 109 | } 110 | if (wandio_printf(wf, "%s%s", delim, asn_buffer) == -1) { 111 | fprintf(stderr, "ERROR: Could not write data to file\n"); 112 | return -1; 113 | } 114 | delim = delim2; 115 | } 116 | return 0; 117 | } 118 | -------------------------------------------------------------------------------- /lib/consumers/bgpview_consumer_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #include 28 | 29 | #ifdef __GNUC__ 30 | #define ATTR_FORMAT_PRINTF(i,j) __attribute__((format(printf, i, j))) 31 | #else 32 | #define ATTR_FORMAT_PRINTF(i,j) /* empty */ 33 | #endif 34 | 35 | #define BVCU_PATH_MAX 1024 36 | #define BVCU_DEFAULT_COMPRESS_LEVEL 6 37 | 38 | /** Open a wandio file for writing. 39 | * 40 | * @param namebuf Pointer to a char[BVCU_PATH_MAX] buffer to hold the filename 41 | * @param fmt printf format string to generate file name 42 | * @param ... printf arguments 43 | * @return Pointer to an iow_t if the file was opened, NULL if an 44 | * error occurred 45 | * 46 | * This function will store a file name into namebuf, generated using fmt and 47 | * the remaining args. 48 | * Then the file will be opened with wandio_wcreate(), with compression type 49 | * automatically determined by the file name. 50 | * 51 | * Any error messages are printed to stderr. 52 | */ 53 | ATTR_FORMAT_PRINTF(2, 3) 54 | iow_t* bvcu_open_outfile(char *namebuf, const char *fmt, ...); 55 | 56 | /** Create an empty file with the given name plus ".done". 57 | * 58 | * @param filename Name of the file to create, without ".done". 59 | * @return 0 for success, -1 for error. 60 | * 61 | * Any error messages are printed to stderr. 62 | */ 63 | int bvcu_create_donefile(const char *filename); 64 | 65 | /** Check that path is the name of an existing writable directory. 66 | * 67 | * @param path Name of the directory to check 68 | * @return 1 for true, 0 for false. 69 | * 70 | * Any error messages are printed to stderr. 71 | */ 72 | int bvcu_is_writable_folder(const char *path); 73 | 74 | /** Write a pfx-peer iterator's AS path to a wandio file. 75 | * 76 | * @param wf the wandio file to write to 77 | * @param it the bgpview pfx-peer iterator with the AS path 78 | * @param delim1 string to print before the first segment 79 | * @param delim2 string to print before the 2nd-Nth segments 80 | * @return 0 for succcess, -1 for error 81 | * 82 | * Any error messages are printed to stderr. 83 | */ 84 | int bvcu_print_pfx_peer_as_path(iow_t *wf, bgpview_iter_t *it, 85 | const char *delim1, const char *delim2); 86 | -------------------------------------------------------------------------------- /lib/consumers/bvc_announcedpfxs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef __BVC_ANNOUNCEDPFXS_H 28 | #define __BVC_ANNOUNCEDPFXS_H 29 | 30 | #include "bgpview_consumer_interface.h" 31 | 32 | /** @file 33 | * 34 | * @brief Header file that exposes the public interface of the bgpview 35 | * Announced Prefixes consumer 36 | * 37 | * @author Alistair King, Chiara Orsini, Adriano Faggiani 38 | * 39 | */ 40 | 41 | BVC_GENERATE_PROTOS(announcedpfxs) 42 | 43 | #endif /* __BVC_ANNOUNCEDPFXS_H */ 44 | -------------------------------------------------------------------------------- /lib/consumers/bvc_archiver.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef __BVC_ARCHIVER_H 28 | #define __BVC_ARCHIVER_H 29 | 30 | #include "bgpview_consumer_interface.h" 31 | 32 | /** @file 33 | * 34 | * @brief Header file that exposes the public interface of the bgpview 35 | * archiver consumer 36 | * 37 | * @author Alistair King 38 | * 39 | */ 40 | 41 | BVC_GENERATE_PROTOS(archiver) 42 | 43 | #endif /* __BVC_ARCHVER_H */ 44 | -------------------------------------------------------------------------------- /lib/consumers/bvc_edges.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef __BVC_EDGES_H 28 | #define __BVC_EDGES_H 29 | 30 | #include "bgpview_consumer_interface.h" 31 | 32 | /** @file 33 | * 34 | * @brief Header file that exposes the public interface of the bgpview 35 | * MOAS consumer 36 | * 37 | * @author Alistair King, Chiara Orsini, Ruwaifa Anwar 38 | * 39 | */ 40 | 41 | BVC_GENERATE_PROTOS(edges) 42 | 43 | #endif /* __BVC_EDGES_H */ 44 | -------------------------------------------------------------------------------- /lib/consumers/bvc_moas.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef __BVC_MOAS_H 28 | #define __BVC_MOAS_H 29 | 30 | #include "bgpview_consumer_interface.h" 31 | 32 | /** @file 33 | * 34 | * @brief Header file that exposes the public interface of the bgpview 35 | * MOAS consumer 36 | * 37 | * @author Alistair King, Chiara Orsini, Ruwaifa Anwar 38 | * 39 | */ 40 | 41 | BVC_GENERATE_PROTOS(moas) 42 | 43 | #endif /* __BVC_MOAS_H */ 44 | -------------------------------------------------------------------------------- /lib/consumers/bvc_myviewprocess.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #include "bgpview_consumer_interface.h" 34 | #include "utils.h" 35 | 36 | #include "bvc_myviewprocess.h" 37 | 38 | #define NAME "my-view-process" 39 | 40 | /* macro to access the current consumer state */ 41 | #define STATE (BVC_GET_STATE(consumer, myviewprocess)) 42 | 43 | /* macro to access the current chain state, i.e. 44 | * the state variables shared by other consumers */ 45 | #define CHAIN_STATE (BVC_GET_CHAIN_STATE(consumer)) 46 | 47 | /* our 'class' */ 48 | static bvc_t bvc_myviewprocess = {BVC_ID_MYVIEWPROCESS, NAME, 49 | BVC_GENERATE_PTRS(myviewprocess)}; 50 | 51 | /* our 'instance' */ 52 | typedef struct bvc_myviewprocess_state { 53 | 54 | /* count how many view have 55 | * been processed */ 56 | int view_counter; 57 | 58 | /* count the number of elements (i.e. 59 | * information in the matrix) 60 | * are present in the current view */ 61 | int current_view_elements; 62 | 63 | } bvc_myviewprocess_state_t; 64 | 65 | /** Print usage information to stderr */ 66 | static void usage(bvc_t *consumer) 67 | { 68 | fprintf(stderr, "consumer usage: %s\n", consumer->name); 69 | } 70 | 71 | /** Parse the arguments given to the consumer */ 72 | static int parse_args(bvc_t *consumer, int argc, char **argv) 73 | { 74 | int opt; 75 | 76 | assert(argc > 0 && argv != NULL); 77 | 78 | /* NB: remember to reset optind to 1 before using getopt! */ 79 | optind = 1; 80 | 81 | /* remember the argv strings DO NOT belong to us */ 82 | while ((opt = getopt(argc, argv, ":?")) >= 0) { 83 | switch (opt) { 84 | case '?': 85 | case ':': 86 | default: 87 | usage(consumer); 88 | return -1; 89 | } 90 | } 91 | 92 | return 0; 93 | } 94 | 95 | /* ==================== CONSUMER INTERFACE FUNCTIONS ==================== */ 96 | 97 | bvc_t *bvc_myviewprocess_alloc() 98 | { 99 | return &bvc_myviewprocess; 100 | } 101 | 102 | int bvc_myviewprocess_init(bvc_t *consumer, int argc, char **argv) 103 | { 104 | bvc_myviewprocess_state_t *state = NULL; 105 | 106 | if ((state = malloc_zero(sizeof(bvc_myviewprocess_state_t))) == NULL) { 107 | return -1; 108 | } 109 | BVC_SET_STATE(consumer, state); 110 | 111 | /* allocate dynamic memory HERE */ 112 | 113 | /* set defaults */ 114 | 115 | state->view_counter = 0; 116 | 117 | state->current_view_elements = 0; 118 | 119 | /* parse the command line args */ 120 | if (parse_args(consumer, argc, argv) != 0) { 121 | goto err; 122 | } 123 | 124 | /* react to args HERE */ 125 | 126 | return 0; 127 | 128 | err: 129 | return -1; 130 | } 131 | 132 | void bvc_myviewprocess_destroy(bvc_t *consumer) 133 | { 134 | bvc_myviewprocess_state_t *state = STATE; 135 | 136 | if (state == NULL) { 137 | return; 138 | } 139 | 140 | /* deallocate dynamic memory HERE */ 141 | 142 | free(state); 143 | 144 | BVC_SET_STATE(consumer, NULL); 145 | } 146 | 147 | int bvc_myviewprocess_process_view(bvc_t *consumer, bgpview_t *view) 148 | { 149 | bvc_myviewprocess_state_t *state = STATE; 150 | bgpview_iter_t *it; 151 | 152 | /* create a new iterator */ 153 | if ((it = bgpview_iter_create(view)) == NULL) { 154 | return -1; 155 | } 156 | 157 | /* increment the number of views processed */ 158 | state->view_counter++; 159 | 160 | /* reset the elements counter */ 161 | state->current_view_elements = 0; 162 | 163 | /* iterate through all peer of the current view 164 | * - active peers only 165 | */ 166 | for (bgpview_iter_first_peer(it, BGPVIEW_FIELD_ACTIVE); 167 | bgpview_iter_has_more_peer(it); bgpview_iter_next_peer(it)) { 168 | /* Information that can be retrieved for the current peer: 169 | * 170 | * PEER NUMERIC ID: 171 | * bgpstream_peer_id_t id = bgpview_iter_peer_get_peer_id(it); 172 | * 173 | * PEER SIGNATURE (i.e. collector, peer ASn, peer IP): 174 | * bgpstream_peer_sig_t *s = bgpview_iter_peer_get_sig(it); 175 | * 176 | * NUMBER OF CURRENTLY ANNOUNCED THE PFX 177 | * int announced_pfxs = bgpview_iter_peer_get_pfx_cnt(it, 0, 178 | * BGPVIEW_FIELD_ACTIVE); 179 | * *0 -> ipv4 + ipv6 180 | * 181 | */ 182 | } 183 | 184 | /* iterate through all prefixes of the current view 185 | * - both ipv4 and ipv6 prefixes are considered 186 | * - active prefixes only (i.e. do not consider prefixes that have 187 | * been withdrawn) 188 | */ 189 | for (bgpview_iter_first_pfx(it, 0 /* all ip versions*/, BGPVIEW_FIELD_ACTIVE); 190 | bgpview_iter_has_more_pfx(it); bgpview_iter_next_pfx(it)) { 191 | 192 | /* Information that can be retrieved for the current prefix: 193 | * 194 | * PREFIX: 195 | * bgpstream_pfx_t *pfx = bgpview_iter_pfx_get_pfx(it) 196 | * 197 | * NUMBER OF PEERS CURRENTLY ANNOUNCING THE PFX 198 | * int peers_cnt = bgpview_iter_pfx_get_peer_cnt(it, BGPVIEW_FIELD_ACTIVE); 199 | */ 200 | 201 | /* iterate over all the peers that currently observe the current pfx */ 202 | for (bgpview_iter_pfx_first_peer(it, BGPVIEW_FIELD_ACTIVE); 203 | bgpview_iter_pfx_has_more_peer(it); bgpview_iter_pfx_next_peer(it)) { 204 | /* Information that can be retrieved for the current element: 205 | * 206 | * ORIGIN ASN: 207 | * int origin_asn = bgpview_iter_pfx_peer_get_orig_asn(it); 208 | */ 209 | 210 | state->current_view_elements++; 211 | } 212 | } 213 | 214 | /* print the number of views processed so far 215 | * FORMAT: num-views: */ 216 | printf("%" PRIu32 " num-views: %d\n", bgpview_get_time(view), 217 | state->view_counter); 218 | 219 | /* print the number of elements in the current view 220 | * FORMAT: num-elements: */ 221 | printf("%" PRIu32 " num-elements: %d\n", bgpview_get_time(view), 222 | state->current_view_elements); 223 | 224 | /* destroy the view iterator */ 225 | bgpview_iter_destroy(it); 226 | 227 | return 0; 228 | } 229 | -------------------------------------------------------------------------------- /lib/consumers/bvc_myviewprocess.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef __BVC_MYVIEWPROCESS_H 28 | #define __BVC_MYVIEWPROCESS_H 29 | 30 | #include "bgpview_consumer_interface.h" 31 | 32 | /** @file 33 | * 34 | * @brief Header file that exposes the public interface of the bgpview 35 | * My View Process consumer 36 | * 37 | * @author Chiara Orsini 38 | * 39 | */ 40 | 41 | BVC_GENERATE_PROTOS(myviewprocess) 42 | 43 | #endif /* __BVC_MYVIEWPROCESS_H */ 44 | -------------------------------------------------------------------------------- /lib/consumers/bvc_pathchange.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef __BVC_PATHCHANGE_H 28 | #define __BVC_PATHCHANGE_H 29 | 30 | #include "bgpview_consumer_interface.h" 31 | 32 | /** @file 33 | * 34 | * @brief Header file that exposes the public interface of the bgpview 35 | * Path Change consumer 36 | * 37 | * @author Alistair King 38 | * 39 | */ 40 | 41 | BVC_GENERATE_PROTOS(pathchange) 42 | 43 | #endif /* __BVC_PATHCHANGE_H */ 44 | -------------------------------------------------------------------------------- /lib/consumers/bvc_peerpfxorigins.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef __BVC_PEERPFXORIGINS_H 28 | #define __BVC_PEERPFXORIGINS_H 29 | 30 | #include "bgpview_consumer_interface.h" 31 | 32 | /** @file 33 | * 34 | * @brief Header file that exposes the public interface of the bgpview 35 | * Per-Peer Prefix Origins consumer 36 | * 37 | * @author Alistair King, Chiara Orsini 38 | * 39 | */ 40 | 41 | BVC_GENERATE_PROTOS(peerpfxorigins) 42 | 43 | #endif /* __BVC_PEERPFXORIGINS_H */ 44 | -------------------------------------------------------------------------------- /lib/consumers/bvc_perasvisibility.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef __BVC_PERASVISIBILITY_H 28 | #define __BVC_PERASVISIBILITY_H 29 | 30 | #include "bgpview_consumer_interface.h" 31 | 32 | /** @file 33 | * 34 | * @brief Header file that exposes the public interface of the bgpview Per-AS 35 | * Visibility consumer 36 | * 37 | * @author Alistair King 38 | * 39 | */ 40 | 41 | BVC_GENERATE_PROTOS(perasvisibility) 42 | 43 | #endif /* __BVC_PERASVISIBILITY_H */ 44 | -------------------------------------------------------------------------------- /lib/consumers/bvc_perfmonitor.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #include "bvc_perfmonitor.h" 28 | #include "bgpview_consumer_interface.h" 29 | #include "bgpstream_utils.h" 30 | #include "utils.h" 31 | #include 32 | #include 33 | #include 34 | 35 | #define NAME "perfmonitor" 36 | 37 | #define BUFFER_LEN 1024 38 | #define META_METRIC_PREFIX_FORMAT "%s.meta.bgpview.consumer." NAME 39 | 40 | #define DUMP_METRIC(value, time, fmt, ...) \ 41 | do { \ 42 | char buf[1024]; \ 43 | snprintf(buf, 1024, META_METRIC_PREFIX_FORMAT "." fmt, __VA_ARGS__); \ 44 | timeseries_set_single(BVC_GET_TIMESERIES(consumer), buf, value, time); \ 45 | } while (0) 46 | 47 | #define STATE (BVC_GET_STATE(consumer, perfmonitor)) 48 | 49 | #define CHAIN_STATE (BVC_GET_CHAIN_STATE(consumer)) 50 | 51 | static bvc_t bvc_perfmonitor = {BVC_ID_PERFMONITOR, NAME, 52 | BVC_GENERATE_PTRS(perfmonitor)}; 53 | 54 | typedef struct bvc_perfmonitor_state { 55 | 56 | /** The number of views we have processed */ 57 | int view_cnt; 58 | 59 | /** Timeseries Key Package (general) */ 60 | timeseries_kp_t *kp_gen; 61 | 62 | } bvc_perfmonitor_state_t; 63 | 64 | #if 0 65 | /** Print usage information to stderr */ 66 | static void usage(bvc_t *consumer) 67 | { 68 | fprintf(stderr, 69 | "consumer usage: %s\n", 70 | /* " -c output compression level to use (default: %d)\n" */ 71 | consumer->name); 72 | } 73 | #endif 74 | 75 | static char *graphite_safe(char *p) 76 | { 77 | if (p == NULL) { 78 | return p; 79 | } 80 | 81 | char *r = p; 82 | while (*p != '\0') { 83 | if (*p == '.') { 84 | *p = '_'; 85 | } 86 | if (*p == '*') { 87 | *p = '-'; 88 | } 89 | p++; 90 | } 91 | return r; 92 | } 93 | 94 | /** Parse the arguments given to the consumer */ 95 | static int parse_args(bvc_t *consumer, int argc, char **argv) 96 | { 97 | /*int opt;*/ 98 | 99 | assert(argc > 0 && argv != NULL); 100 | 101 | /* NB: remember to reset optind to 1 before using getopt! */ 102 | optind = 1; 103 | 104 | return 0; 105 | } 106 | 107 | bvc_t *bvc_perfmonitor_alloc() 108 | { 109 | return &bvc_perfmonitor; 110 | } 111 | 112 | int bvc_perfmonitor_init(bvc_t *consumer, int argc, char **argv) 113 | { 114 | bvc_perfmonitor_state_t *state = NULL; 115 | 116 | if ((state = malloc_zero(sizeof(bvc_perfmonitor_state_t))) == NULL) { 117 | return -1; 118 | } 119 | BVC_SET_STATE(consumer, state); 120 | 121 | /* set defaults here */ 122 | 123 | state->view_cnt = 0; 124 | 125 | /* parse the command line args */ 126 | if (parse_args(consumer, argc, argv) != 0) { 127 | return -1; 128 | } 129 | 130 | /* react to args here */ 131 | 132 | return 0; 133 | } 134 | 135 | void bvc_perfmonitor_destroy(bvc_t *consumer) 136 | { 137 | bvc_perfmonitor_state_t *state = STATE; 138 | 139 | fprintf(stderr, "BWC-TEST: %d views processed\n", STATE->view_cnt); 140 | 141 | if (state == NULL) { 142 | return; 143 | } 144 | 145 | /* destroy things here */ 146 | 147 | free(state); 148 | 149 | BVC_SET_STATE(consumer, NULL); 150 | } 151 | 152 | int bvc_perfmonitor_process_view(bvc_t *consumer, bgpview_t *view) 153 | { 154 | // view arrival delay, i.e. now - table ts 155 | uint32_t time_begin = epoch_sec(); 156 | DUMP_METRIC(time_begin - bgpview_get_time(view), bgpview_get_time(view), "%s", 157 | CHAIN_STATE->metric_prefix, "view_arrival_delay"); 158 | 159 | // get the number of peers and their table size 160 | 161 | bgpview_iter_t *it; 162 | 163 | /* create a new iterator */ 164 | if ((it = bgpview_iter_create(view)) == NULL) { 165 | return -1; 166 | } 167 | 168 | bgpstream_peer_sig_t *sig; 169 | unsigned long long pfx4_cnt; 170 | unsigned long long pfx6_cnt; 171 | unsigned long long peer_on = 1; 172 | 173 | char addr[INET6_ADDRSTRLEN] = ""; 174 | 175 | for (bgpview_iter_first_peer(it, BGPVIEW_FIELD_ACTIVE); 176 | bgpview_iter_has_more_peer(it); bgpview_iter_next_peer(it)) { 177 | /* grab the peer id */ 178 | sig = bgpview_iter_peer_get_sig(it); 179 | assert(sig != NULL); 180 | pfx4_cnt = bgpview_iter_peer_get_pfx_cnt(it, BGPSTREAM_ADDR_VERSION_IPV4, 181 | BGPVIEW_FIELD_ACTIVE); 182 | pfx6_cnt = bgpview_iter_peer_get_pfx_cnt(it, BGPSTREAM_ADDR_VERSION_IPV6, 183 | BGPVIEW_FIELD_ACTIVE); 184 | 185 | bgpstream_addr_ntop(addr, INET6_ADDRSTRLEN, &(sig->peer_ip_addr)); 186 | graphite_safe(addr); 187 | DUMP_METRIC(peer_on, bgpview_get_time(view), "peers.%s.%s.peer_on", 188 | CHAIN_STATE->metric_prefix, sig->collector_str, addr); 189 | 190 | DUMP_METRIC(pfx4_cnt, bgpview_get_time(view), "peers.%s.%s.ipv4_cnt", 191 | CHAIN_STATE->metric_prefix, sig->collector_str, addr); 192 | 193 | DUMP_METRIC(pfx6_cnt, bgpview_get_time(view), "peers.%s.%s.ipv6_cnt", 194 | CHAIN_STATE->metric_prefix, sig->collector_str, addr); 195 | } 196 | 197 | /* destroy the view iterator */ 198 | bgpview_iter_destroy(it); 199 | 200 | STATE->view_cnt++; 201 | 202 | uint32_t time_end = epoch_sec(); 203 | 204 | DUMP_METRIC(time_end - time_begin, bgpview_get_time(view), "%s", 205 | CHAIN_STATE->metric_prefix, "processing_time"); 206 | 207 | return 0; 208 | } 209 | -------------------------------------------------------------------------------- /lib/consumers/bvc_perfmonitor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef __BVC_PERFMONITOR_H 28 | #define __BVC_PERFMONITOR_H 29 | 30 | #include "bgpview_consumer_interface.h" 31 | 32 | /** @file 33 | * 34 | * @brief Header file that exposes the public interface of the bgpview 35 | * performance monitor consumer 36 | * 37 | * @author Alistair King 38 | * 39 | */ 40 | 41 | BVC_GENERATE_PROTOS(perfmonitor) 42 | 43 | #endif /* __BVC_PERFMONITOR_H */ 44 | -------------------------------------------------------------------------------- /lib/consumers/bvc_pergeovisibility.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef __BVC_PERGEOVISIBILITY_H 28 | #define __BVC_PERGEOVISIBILITY_H 29 | 30 | #include "bgpview_consumer_interface.h" 31 | 32 | /** @file 33 | * 34 | * @brief Header file that exposes the public interface of the bgpview Per-Geo 35 | * Visibility consumer 36 | * 37 | * @author Chiara Orsini 38 | * 39 | */ 40 | 41 | BVC_GENERATE_PROTOS(pergeovisibility) 42 | 43 | #endif /* __BVC_PERGEOVISIBILITY_H */ 44 | -------------------------------------------------------------------------------- /lib/consumers/bvc_pfx2as.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef __BVC_PFX2AS_H 28 | #define __BVC_PFX2AS_H 29 | 30 | #include "bgpview_consumer_interface.h" 31 | 32 | /** @file 33 | * 34 | * @brief Header file that exposes the public interface of the bgpview 35 | * Prefix-to-AS consumer 36 | * 37 | * @author Ken Keys 38 | * 39 | */ 40 | 41 | BVC_GENERATE_PROTOS(pfx2as) 42 | 43 | #endif /* __BVC_PFX2AS_H */ 44 | -------------------------------------------------------------------------------- /lib/consumers/bvc_pfxorigins.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef __BVC_PFXORIGINS_H 28 | #define __BVC_PFXORIGINS_H 29 | 30 | #include "bgpview_consumer_interface.h" 31 | 32 | /** @file 33 | * 34 | * @brief Header file that exposes the public interface of the bgpview 35 | * Announced Prefixes consumer 36 | * 37 | * @author Alistair King, Chiara Orsini 38 | * 39 | */ 40 | 41 | BVC_GENERATE_PROTOS(pfxorigins) 42 | 43 | #endif /* __BVC_PFXORIGINS_H */ 44 | -------------------------------------------------------------------------------- /lib/consumers/bvc_routedspace.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef __BVC_ROUTEDSPACE_H 28 | #define __BVC_ROUTEDSPACE_H 29 | 30 | #include "bgpview_consumer_interface.h" 31 | 32 | /** @file 33 | * 34 | * @brief Header file that exposes the public interface of the bgpview 35 | * Route Space Monitor consumer 36 | * 37 | * @author Chiara Orsini, Pierre-Antoine Vervier 38 | * 39 | */ 40 | 41 | BVC_GENERATE_PROTOS(routedspace) 42 | 43 | #endif /* __BVC_ROUTEDSPACE_H */ 44 | -------------------------------------------------------------------------------- /lib/consumers/bvc_subpfx.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef __BVC_SUBPFX_H 28 | #define __BVC_SUBPFX_H 29 | 30 | #include "bgpview_consumer_interface.h" 31 | 32 | /** @file 33 | * 34 | * @brief Header file that exposes the public interface of the bgpview 35 | * Sub-prefix (submoas and "defcon") consumer 36 | * 37 | * @author Alistair King 38 | * 39 | */ 40 | 41 | BVC_GENERATE_PROTOS(subpfx) 42 | 43 | #endif /* __BVC_SUBPFX_H */ 44 | -------------------------------------------------------------------------------- /lib/consumers/bvc_test.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef __BVC_TEST_H 28 | #define __BVC_TEST_H 29 | 30 | #include "bgpview_consumer_interface.h" 31 | 32 | /** @file 33 | * 34 | * @brief Header file that exposes the public interface of the bgpview test 35 | * consumer 36 | * 37 | * @author Alistair King 38 | * 39 | */ 40 | 41 | BVC_GENERATE_PROTOS(test) 42 | 43 | #endif /* __BVC_TEST_H */ 44 | -------------------------------------------------------------------------------- /lib/consumers/bvc_triplets.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef __BVC_TRIPLETS_H 28 | #define __BVC_TRIPLETS_H 29 | 30 | #include "bgpview_consumer_interface.h" 31 | 32 | /** @file 33 | * 34 | * @brief Header file that exposes the public interface of the bgpview 35 | * Triplets consumer 36 | * 37 | * @author Alistair King, Chiara Orsini, Ruwaifa Anwar 38 | * 39 | */ 40 | 41 | BVC_GENERATE_PROTOS(triplets) 42 | 43 | #endif /* __BVC_TRIPLETS_H */ 44 | -------------------------------------------------------------------------------- /lib/consumers/bvc_viewsender.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef __BVC_VIEWSENDER_H 28 | #define __BVC_VIEWSENDER_H 29 | 30 | #include "bgpview_consumer_interface.h" 31 | 32 | /** @file 33 | * 34 | * @brief Header file that exposes the public interface of the BGPView Sender 35 | * 36 | * @author Danilo Giordano, Alistair King 37 | * 38 | */ 39 | 40 | BVC_GENERATE_PROTOS(viewsender) 41 | 42 | #endif /* __BVC_VIEWSENDER_H */ 43 | -------------------------------------------------------------------------------- /lib/consumers/bvc_visibility.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef __BVC_VISIBILITY_H 28 | #define __BVC_VISIBILITY_H 29 | 30 | #include "bgpview_consumer_interface.h" 31 | 32 | /** @file 33 | * 34 | * @brief Header file that exposes the public interface of the bgpview 35 | * Visibility consumer 36 | * 37 | * @author Chiara Orsini 38 | * 39 | */ 40 | 41 | BVC_GENERATE_PROTOS(visibility) 42 | 43 | #endif /* __BVC_VISIBILITY_H */ 44 | -------------------------------------------------------------------------------- /lib/io/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2014 The Regents of the University of California. 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions are met: 6 | # 7 | # 1. Redistributions of source code must retain the above copyright notice, 8 | # this list of conditions and the following disclaimer. 9 | # 10 | # 2. Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | # POSSIBILITY OF SUCH DAMAGE. 25 | # 26 | 27 | SUBDIRS = 28 | 29 | AM_CPPFLAGS = -I$(top_srcdir) \ 30 | -I$(top_srcdir)/common \ 31 | -I$(top_srcdir)/lib 32 | 33 | noinst_LTLIBRARIES = libbgpview_io.la 34 | 35 | include_HEADERS = bgpview_io.h 36 | 37 | libbgpview_io_la_SOURCES = \ 38 | bgpview_io.c \ 39 | bgpview_io.h 40 | 41 | MOD_LIBS= 42 | 43 | if WITH_BGPVIEW_IO_FILE 44 | SUBDIRS+=file 45 | MOD_LIBS+=$(top_builddir)/lib/io/file/libbgpview_io_file.la 46 | endif 47 | 48 | if WITH_BGPVIEW_IO_ZMQ 49 | SUBDIRS+=zmq 50 | MOD_LIBS+=$(top_builddir)/lib/io/zmq/libbgpview_io_zmq.la 51 | endif 52 | 53 | if WITH_BGPVIEW_IO_KAFKA 54 | SUBDIRS+=kafka 55 | MOD_LIBS+=$(top_builddir)/lib/io/kafka/libbgpview_io_kafka.la 56 | endif 57 | 58 | if WITH_BGPVIEW_IO_BSRT 59 | SUBDIRS+=bsrt 60 | MOD_LIBS+=$(top_builddir)/lib/io/bsrt/libbgpview_io_bsrt.la 61 | endif 62 | 63 | if WITH_BGPVIEW_IO_TEST 64 | SUBDIRS+=test 65 | MOD_LIBS+=$(top_builddir)/lib/io/test/libbgpview_io_test.la 66 | endif 67 | 68 | libbgpview_io_la_LIBADD = \ 69 | $(MOD_LIBS) 70 | 71 | 72 | ACLOCAL_AMFLAGS = -I m4 73 | 74 | CLEANFILES = *~ 75 | -------------------------------------------------------------------------------- /lib/io/bsrt/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2014 The Regents of the University of California. 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions are met: 6 | # 7 | # 1. Redistributions of source code must retain the above copyright notice, 8 | # this list of conditions and the following disclaimer. 9 | # 10 | # 2. Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | # POSSIBILITY OF SUCH DAMAGE. 25 | # 26 | 27 | SUBDIRS = libbgpcorsaro 28 | 29 | AM_CPPFLAGS = -I$(top_srcdir) \ 30 | -I$(top_srcdir)/common \ 31 | -I$(top_srcdir)/lib \ 32 | -I$(top_srcdir)/lib/io 33 | 34 | noinst_LTLIBRARIES = libbgpview_io_bsrt.la 35 | 36 | include_HEADERS = 37 | 38 | libbgpview_io_bsrt_la_SOURCES = \ 39 | bgpview_io_bsrt.c \ 40 | bgpview_io_bsrt.h \ 41 | bgpview_io_bsrt_int.h 42 | 43 | libbgpview_io_bsrt_la_LIBADD = 44 | libbgpview_io_bsrt_la_LIBADD += $(top_srcdir)/lib/io/bsrt/libbgpcorsaro/libbgpcorsaro.la 45 | AM_CPPFLAGS += -I$(top_srcdir)/lib/io/bsrt/libbgpcorsaro 46 | 47 | 48 | ACLOCAL_AMFLAGS = -I m4 49 | 50 | CLEANFILES = *~ 51 | -------------------------------------------------------------------------------- /lib/io/bsrt/bgpview_io_bsrt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef __BGPVIEW_IO_BSRT_H 28 | #define __BGPVIEW_IO_BSRT_H 29 | 30 | #include "bgpview.h" 31 | #include "bgpview_io.h" 32 | #include "timeseries.h" 33 | 34 | /** @file 35 | * 36 | * @brief Header file that exposes the public interface of the bgpview BSRT 37 | * client 38 | * 39 | * @author Ken Keys 40 | * 41 | */ 42 | 43 | /** 44 | * @name Public Constants 45 | * 46 | * @{ */ 47 | 48 | 49 | /** @} */ 50 | 51 | /** 52 | * @name Public Opaque Data Structures 53 | * 54 | * @{ */ 55 | 56 | /** Opaque structure representing a BGPView BSRT IO instance */ 57 | typedef struct bgpview_io_bsrt bgpview_io_bsrt_t; 58 | 59 | /** @} */ 60 | 61 | /** 62 | * @name Public Data Structures 63 | * 64 | * @{ */ 65 | 66 | /** @} */ 67 | 68 | /** 69 | * @name Public Enums 70 | * 71 | * @{ */ 72 | 73 | /** @} */ 74 | 75 | /** Initialize a new BGPView BSRT IO client 76 | * 77 | * @param opts string containing options to be parsed with getopt 78 | * @param timeseries pointer to shared timeseries 79 | * @return a pointer to a BGPView BSRT IO instance if successful, NULL if an 80 | * error occurred. 81 | */ 82 | bgpview_io_bsrt_t *bgpview_io_bsrt_init(const char *opts, timeseries_t *timeseries); 83 | 84 | /** Destroy the given BGPView BSRT IO client 85 | * 86 | * @param client pointer to the bgpview BSRT client instance to free 87 | */ 88 | void bgpview_io_bsrt_destroy(bgpview_io_bsrt_t *client); 89 | 90 | /** Start the given bgpview BSRT client 91 | * 92 | * @param client pointer to a BSRT client instance to start 93 | * @return 0 if the client started successfully, -1 otherwise. 94 | */ 95 | int bgpview_io_bsrt_start(bgpview_io_bsrt_t *client); 96 | 97 | /** Attempt to receive a BGP View from BSRT 98 | * 99 | * @param client pointer to the client instance to receive from 100 | * @return 0 or -1 if an error occurred. 101 | * 102 | * The view provided to this function must have been returned by 103 | * bgpview_io_bsrt_get_view_ptr(). 104 | */ 105 | int bgpview_io_bsrt_recv_view(bgpview_io_bsrt_t *client); 106 | 107 | /** Return a pointer to the view */ 108 | bgpview_t *bgpview_io_bsrt_get_view_ptr(bgpview_io_bsrt_t *client); 109 | 110 | #endif /* __BGPVIEW_IO_BSRT_H */ 111 | -------------------------------------------------------------------------------- /lib/io/bsrt/bgpview_io_bsrt_int.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef __BGPVIEW_IO_BSRT_INT_H 28 | #define __BGPVIEW_IO_BSRT_INT_H 29 | 30 | #include "bgpstream.h" 31 | 32 | extern int (*bsrt_get_next_record)(bgpstream_t *, bgpstream_record_t **); 33 | extern int (*bsrt_record_get_next_elem)(bgpstream_record_t *, bgpstream_elem_t **); 34 | 35 | #endif // __BGPVIEW_IO_BSRT_INT_H 36 | -------------------------------------------------------------------------------- /lib/io/bsrt/libbgpcorsaro/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2014 The Regents of the University of California. 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions are met: 6 | # 7 | # 1. Redistributions of source code must retain the above copyright notice, 8 | # this list of conditions and the following disclaimer. 9 | # 10 | # 2. Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | # POSSIBILITY OF SUCH DAMAGE. 25 | # 26 | 27 | SUBDIRS = plugins 28 | AM_CPPFLAGS = -I$(top_srcdir) \ 29 | -I$(top_srcdir)/lib \ 30 | -Iplugins \ 31 | -I$(top_srcdir)/common 32 | 33 | noinst_LTLIBRARIES = libbgpcorsaro.la 34 | 35 | libbgpcorsaro_la_SOURCES = \ 36 | bgpcorsaro.c \ 37 | bgpcorsaro.h \ 38 | bgpcorsaro_int.h \ 39 | bgpcorsaro_io.c \ 40 | bgpcorsaro_io.h \ 41 | bgpcorsaro_log.c \ 42 | bgpcorsaro_log.h \ 43 | bgpcorsaro_plugin.h 44 | 45 | libbgpcorsaro_la_LIBADD = plugins/libbgpcorsaroplugins.la 46 | 47 | ACLOCAL_AMFLAGS = -I m4 48 | 49 | CLEANFILES = *~ 50 | -------------------------------------------------------------------------------- /lib/io/bsrt/libbgpcorsaro/bgpcorsaro_int.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | #ifndef __BGPCORSARO_INT_H 27 | #define __BGPCORSARO_INT_H 28 | 29 | #include "bgpcorsaro.h" 30 | #include "bgpstream.h" 31 | #include "bgpview.h" 32 | #include "config.h" 33 | 34 | /** @file 35 | * 36 | * @brief Header file dealing with internal bgpcorsaro functions 37 | * 38 | * @author Alistair King 39 | * 40 | */ 41 | 42 | 43 | /* GCC optimizations */ 44 | /** @todo either make use of those that libtrace defines, or copy the way that 45 | libtrace does this*/ 46 | #if __GNUC__ >= 3 47 | #ifndef DEPRECATED 48 | #define DEPRECATED __attribute__((deprecated)) 49 | #endif 50 | #ifndef SIMPLE_FUNCTION 51 | #define SIMPLE_FUNCTION __attribute__((pure)) 52 | #endif 53 | #ifndef UNUSED 54 | #define UNUSED __attribute__((unused)) 55 | #endif 56 | #ifndef PACKED 57 | #define PACKED __attribute__((packed)) 58 | #endif 59 | #ifndef PRINTF 60 | #define PRINTF(formatpos, argpos) \ 61 | __attribute__((format(printf, formatpos, argpos))) 62 | #endif 63 | #else 64 | #ifndef DEPRECATED 65 | #define DEPRECATED 66 | #endif 67 | #ifndef SIMPLE_FUNCTION 68 | #define SIMPLE_FUNCTION 69 | #endif 70 | #ifndef UNUSED 71 | #define UNUSED 72 | #endif 73 | #ifndef PACKED 74 | #define PACKED 75 | #endif 76 | #ifndef PRINTF 77 | #define PRINTF(formatpos, argpos) 78 | #endif 79 | #endif 80 | 81 | /** 82 | * @name Bgpcorsaro data structures 83 | * 84 | * These data structures are used when reading bgpcorsaro files with 85 | * libbgpcorsaro 86 | * 87 | * @{ */ 88 | 89 | /** Structure representing the start or end of an interval 90 | * 91 | * The start time represents the first second which this interval covers. 92 | * I.e. start.time <= pkt.time for all pkt in the interval 93 | * The end time represents the last second which this interval covers. 94 | * I.e. end.time >= pkt.time for all pkt in the interval 95 | * 96 | * If looking at the start and end interval records for a given interval, 97 | * the interval duration will be: 98 | * @code end.time - start.time + 1 @endcode 99 | * The +1 includes the final second in the time. 100 | * 101 | * If bgpcorsaro is shutdown at any time other than an interval boundary, the 102 | * end.time value will be the seconds component of the arrival time of the 103 | * last observed record. 104 | * 105 | * Values are all in HOST byte order 106 | */ 107 | struct bgpcorsaro_interval { 108 | /** The interval number (starts at 0) */ 109 | uint16_t number; 110 | /** The time this interval started/ended */ 111 | uint32_t time; 112 | }; 113 | 114 | /** @} */ 115 | 116 | /** The interval after which we will end an interval */ 117 | #define BGPCORSARO_INTERVAL_DEFAULT 60 118 | 119 | /** Length of buffer for gethostname() */ 120 | #define BGPCORSARO_HOST_NAME_MAX 255 121 | 122 | /** Bgpcorsaro output state */ 123 | struct bgpcorsaro { 124 | /** The local wall time that bgpcorsaro was started at */ 125 | struct timeval init_time; 126 | 127 | /** The bgpstream pointer for the stream that we are being fed from */ 128 | bgpstream_t *stream; 129 | 130 | /** The name of the monitor that bgpcorsaro is running on */ 131 | char monitorname[BGPCORSARO_HOST_NAME_MAX+1]; 132 | 133 | /** The template used to create bgpcorsaro output files */ 134 | char *template; 135 | 136 | /** The compression type (based on the file name) */ 137 | int compress; 138 | 139 | /** The compression level (ignored if not compressing) */ 140 | int compress_level; 141 | 142 | /** The file to write log output to */ 143 | iow_t *logfile; 144 | 145 | /** Has the user asked us not to log to a file? */ 146 | int logfile_disabled; 147 | 148 | /** A borrowed pointer to a libtimeseries instance */ 149 | timeseries_t *timeseries; 150 | 151 | /** A pointer to the record passed to the plugins */ 152 | bgpstream_record_t *bsrecord; 153 | 154 | /** The first interval end will be rounded down to the nearest integer 155 | multiple of the interval length if enabled */ 156 | int align_intervals; 157 | 158 | /** The number of seconds after which plugins will be asked to dump data */ 159 | int interval; 160 | 161 | /** The output files will be rotated after n intervals if >0 */ 162 | int output_rotate; 163 | 164 | /** The meta output files will be rotated after n intervals if >=0 165 | * a value of 0 indicates no rotation, <0 indicates the output_rotate 166 | * value should be used 167 | */ 168 | int meta_output_rotate; 169 | 170 | /** State for the current interval */ 171 | bgpcorsaro_interval_t interval_start; 172 | 173 | /** The time that this interval will be dumped at */ 174 | long next_report; 175 | 176 | /** The time of the the first record seen by bgpcorsaro */ 177 | long first_ts; 178 | 179 | /** The time of the most recent record seen by bgpcorsaro */ 180 | long last_ts; 181 | 182 | /** Whether there are un-dumped records in the current interval */ 183 | int interval_end_needed; 184 | 185 | /** The total number of records that have been processed */ 186 | uint64_t record_cnt; 187 | 188 | /** Has this bgpcorsaro object been started yet? */ 189 | int started; 190 | 191 | /** Has this bgpcorsaro reached EOF? */ 192 | int eof; 193 | 194 | /** Minimum record time allowed */ 195 | uint32_t minimum_time; 196 | 197 | /** Maximum allowed packet inter-arrival time */ 198 | int gap_limit; 199 | 200 | /** Shared bgpview */ 201 | bgpview_t *shared_view; 202 | }; 203 | 204 | #ifdef WITH_PLUGIN_TIMING 205 | /* Helper macros for doing timing */ 206 | 207 | /** Start a timer with the given name */ 208 | #define TIMER_START(timer) \ 209 | struct timeval timer_start; \ 210 | do { \ 211 | gettimeofday(&timer_start, NULL); \ 212 | } while (0) 213 | 214 | #define TIMER_END(timer) \ 215 | struct timeval timer_end, timer_diff; \ 216 | do { \ 217 | gettimeofday(&timer_end, NULL); \ 218 | timeval_subtract(&timer_diff, &timer_end, &timer_start); \ 219 | } while (0) 220 | 221 | #define TIMER_VAL(timer) ((timer_diff.tv_sec * 1000000) + timer_diff.tv_usec) 222 | #endif 223 | 224 | #endif /* __BGPCORSARO_INT_H */ 225 | -------------------------------------------------------------------------------- /lib/io/bsrt/libbgpcorsaro/bgpcorsaro_io.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | #ifndef __BGPCORSARO_IO_H 27 | #define __BGPCORSARO_IO_H 28 | 29 | #include "config.h" 30 | 31 | #include "bgpcorsaro_int.h" 32 | 33 | #include "bgpcorsaro_plugin.h" 34 | 35 | /** @file 36 | * 37 | * @brief Header file dealing with the bgpcorsaro file IO 38 | * 39 | * @author Alistair King 40 | * 41 | */ 42 | 43 | /** The character to replace with the name of the plugin */ 44 | #define BGPCORSARO_IO_PLUGIN_PATTERN 'X' 45 | /** The pattern to replace in the output file name with the name of the plugin 46 | */ 47 | #define BGPCORSARO_IO_PLUGIN_PATTERN_STR "%X" 48 | 49 | /** The character to replace with the monitor name */ 50 | #define BGPCORSARO_IO_MONITOR_PATTERN 'N' 51 | /** The pattern to replace in the output file name with monitor name */ 52 | #define BGPCORSARO_IO_MONITOR_PATTERN_STR "%N" 53 | 54 | /** The name to use for the log 'plugin' file */ 55 | #define BGPCORSARO_IO_LOG_NAME "log" 56 | 57 | /** Uses the given settings to open an bgpcorsaro file for the given plugin 58 | * 59 | * @param bgpcorsaro The bgpcorsaro object associated with the file 60 | * @param plugin_name The name of the plugin (inserted into the template) 61 | * @param interval The first interval start time represented in the file 62 | * (inserted into the template) 63 | * @param compress The wandio file compression type to use 64 | * @param compress_level The wandio file compression level to use 65 | * @param flags The flags to use when opening the file (e.g. O_CREAT) 66 | * @return A pointer to a new wandio output file, or NULL if an error occurs 67 | */ 68 | iow_t *bgpcorsaro_io_prepare_file_full(bgpcorsaro_t *bgpcorsaro, 69 | const char *plugin_name, 70 | bgpcorsaro_interval_t *interval, 71 | int compress, int compress_level, 72 | int flags); 73 | 74 | /** Uses the current settings to open an bgpcorsaro file for the given plugin 75 | * 76 | * @param bgpcorsaro The bgpcorsaro object associated with the file 77 | * @param plugin_name The name of the plugin (inserted into the template) 78 | * @param interval The first interval start time represented in the file 79 | * (inserted into the template) 80 | * @return A pointer to a new wandio output file, or NULL if an error occurs 81 | */ 82 | iow_t *bgpcorsaro_io_prepare_file(bgpcorsaro_t *bgpcorsaro, 83 | const char *plugin_name, 84 | bgpcorsaro_interval_t *interval); 85 | 86 | /** Validates a output file template for needed features 87 | * 88 | * @param bgpcorsaro The bgpcorsaro object associated with the template 89 | * @param template The file template to be validated 90 | * @return 1 if the template is valid, 0 if it is invalid 91 | */ 92 | int bgpcorsaro_io_validate_template(bgpcorsaro_t *bgpcorsaro, char *template); 93 | 94 | /** Determines whether there are any time-related patterns in the file template. 95 | * 96 | * @param bgpcorsaro The bgpcorsaro object to check 97 | * @return 1 if there are time-related patterns, 0 if not 98 | */ 99 | int bgpcorsaro_io_template_has_timestamp(bgpcorsaro_t *bgpcorsaro); 100 | 101 | /** Write the appropriate interval headers to the file 102 | * 103 | * @param bgpcorsaro The bgpcorsaro object associated with the file 104 | * @param file The wandio output file to write to 105 | * @param int_start The start interval to write out 106 | * @return The amount of data written, or -1 if an error occurs 107 | */ 108 | off_t bgpcorsaro_io_write_interval_start(bgpcorsaro_t *bgpcorsaro, iow_t *file, 109 | bgpcorsaro_interval_t *int_start); 110 | 111 | /** Write the appropriate interval trailers to the file 112 | * 113 | * @param bgpcorsaro The bgpcorsaro object associated with the file 114 | * @param file The wandio output file to write to 115 | * @param int_end The end interval to write out 116 | * @return The amount of data written, or -1 if an error occurs 117 | */ 118 | off_t bgpcorsaro_io_write_interval_end(bgpcorsaro_t *bgpcorsaro, iow_t *file, 119 | bgpcorsaro_interval_t *int_end); 120 | 121 | /** Write the appropriate plugin header to the file 122 | * 123 | * @param bgpcorsaro The bgpcorsaro object associated with the file 124 | * @param file The wandio output file to write to 125 | * @param plugin The plugin object to write a start record for 126 | * @return The amount of data written, or -1 if an error occurs 127 | */ 128 | off_t bgpcorsaro_io_write_plugin_start(bgpcorsaro_t *bgpcorsaro, iow_t *file, 129 | bgpcorsaro_plugin_t *plugin); 130 | 131 | /** Write the appropriate plugin trailer to the file 132 | * 133 | * @param bgpcorsaro The bgpcorsaro object associated with the file 134 | * @param file The wandio output file to write to 135 | * @param plugin The plugin object to write an end record for 136 | * @return The amount of data written, or -1 if an error occurs 137 | */ 138 | off_t bgpcorsaro_io_write_plugin_end(bgpcorsaro_t *bgpcorsaro, iow_t *file, 139 | bgpcorsaro_plugin_t *plugin); 140 | 141 | #endif /* __BGPCORSARO_IO_H */ 142 | -------------------------------------------------------------------------------- /lib/io/bsrt/libbgpcorsaro/bgpcorsaro_log.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | #include "bgpcorsaro_int.h" 27 | #include "config.h" 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | #ifdef HAVE_SYS_TIME_H 41 | #include 42 | #endif 43 | #ifdef HAVE_TIME_H 44 | #include 45 | #endif 46 | 47 | #include "utils.h" 48 | 49 | #include "bgpcorsaro_io.h" 50 | #include "bgpcorsaro_log.h" 51 | 52 | static char *timestamp_str(char *buf, const size_t len) 53 | { 54 | struct timeval tv; 55 | struct tm *tm; 56 | 57 | buf[0] = '\0'; 58 | gettimeofday(&tv, NULL); 59 | if ((tm = localtime(&tv.tv_sec)) == NULL) 60 | return buf; 61 | 62 | int ms = tv.tv_usec / 1000; 63 | snprintf(buf, len, "[%02d:%02d:%02d:%03d] ", tm->tm_hour, tm->tm_min, 64 | tm->tm_sec, ms); 65 | 66 | return buf; 67 | } 68 | 69 | ATTR_FORMAT_PRINTF(3, 0) 70 | static void generic_log(const char *func, iow_t *logfile, const char *format, 71 | va_list ap) 72 | { 73 | char message[512]; 74 | char ts[16]; 75 | char fs[64]; 76 | 77 | assert(format != NULL); 78 | 79 | vsnprintf(message, sizeof(message), format, ap); 80 | 81 | timestamp_str(ts, sizeof(ts)); 82 | 83 | if (func != NULL) 84 | snprintf(fs, sizeof(fs), "%s: ", func); 85 | else 86 | fs[0] = '\0'; 87 | 88 | if (logfile == NULL) { 89 | fprintf(stderr, "%s%s%s\n", ts, fs, message); 90 | fflush(stderr); 91 | } else { 92 | wandio_printf(logfile, "%s%s%s\n", ts, fs, message); 93 | /*wandio_flush(logfile);*/ 94 | wandio_wflush(logfile); // XXX 95 | 96 | #ifdef DEBUG 97 | /* we've been asked to dump debugging information */ 98 | fprintf(stderr, "%s%s%s\n", ts, fs, message); 99 | fflush(stderr); 100 | #endif 101 | } 102 | } 103 | 104 | void bgpcorsaro_log_va(const char *func, bgpcorsaro_t *bc, 105 | const char *format, va_list args) 106 | { 107 | iow_t *lf = (bc == NULL) ? NULL : bc->logfile; 108 | generic_log(func, lf, format, args); 109 | } 110 | 111 | void bgpcorsaro_log(const char *func, bgpcorsaro_t *bc, const char *format, ...) 112 | { 113 | va_list ap; 114 | va_start(ap, format); 115 | bgpcorsaro_log_va(func, bc, format, ap); 116 | va_end(ap); 117 | } 118 | 119 | void bgpcorsaro_log_file(const char *func, iow_t *logfile, const char *format, 120 | ...) 121 | { 122 | va_list ap; 123 | va_start(ap, format); 124 | generic_log(func, logfile, format, ap); 125 | va_end(ap); 126 | } 127 | 128 | int bgpcorsaro_log_init(bgpcorsaro_t *bc) 129 | { 130 | if ((bc->logfile = bgpcorsaro_io_prepare_file_full(bc, BGPCORSARO_IO_LOG_NAME, 131 | &bc->interval_start, WANDIO_COMPRESS_NONE, 0, O_CREAT)) == NULL) { 132 | fprintf(stderr, "could not open log for writing\n"); 133 | return -1; 134 | } 135 | return 0; 136 | } 137 | 138 | void bgpcorsaro_log_close(bgpcorsaro_t *bc) 139 | { 140 | if (bc->logfile != NULL) { 141 | wandio_wdestroy(bc->logfile); 142 | bc->logfile = NULL; 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /lib/io/bsrt/libbgpcorsaro/bgpcorsaro_log.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | #ifndef __BGPCORSARO_LOG_H 27 | #define __BGPCORSARO_LOG_H 28 | 29 | #include "config.h" 30 | 31 | #include 32 | 33 | #include "bgpcorsaro_int.h" 34 | 35 | /** @file 36 | * 37 | * @brief Header file dealing with the bgpcorsaro logging sub-system 38 | * 39 | * @author Alistair King 40 | * 41 | */ 42 | 43 | #ifdef __GNUC__ 44 | #define ATTR_FORMAT_PRINTF(i,j) __attribute__((format(printf, i, j))) 45 | #else 46 | #define ATTR_FORMAT_PRINTF(i,j) /* empty */ 47 | #endif 48 | 49 | /** Write a formatted string to the logfile associated with an bgpcorsaro object 50 | * 51 | * @param func The name of the calling function (__func__) 52 | * @param bgpcorsaro The bgpcorsaro output object to log for 53 | * @param format The printf style formatting string 54 | * @param args Variable list of arguments to the format string 55 | * 56 | * This function takes the same style of arguments that printf(3) does. 57 | */ 58 | ATTR_FORMAT_PRINTF(3, 0) 59 | void bgpcorsaro_log_va(const char *func, bgpcorsaro_t *bgpcorsaro, 60 | const char *format, va_list args); 61 | 62 | /** Write a formatted string to the logfile associated with an bgpcorsaro object 63 | * 64 | * @param func The name of the calling function (__func__) 65 | * @param bgpcorsaro The bgpcorsaro output object to log for 66 | * @param format The printf style formatting string 67 | * @param ... Variable list of arguments to the format string 68 | * 69 | * This function takes the same style of arguments that printf(3) does. 70 | */ 71 | void bgpcorsaro_log(const char *func, bgpcorsaro_t *bgpcorsaro, 72 | const char *format, ...) ATTR_FORMAT_PRINTF(3, 4); 73 | 74 | /** Write a formatted string to a generic log file 75 | * 76 | * @param func The name of the calling function (__func__) 77 | * @param logfile The file to log to (STDERR if NULL is passed) 78 | * @param format The printf style formatting string 79 | * @param ... Variable list of arguments to the format string 80 | * 81 | * This function takes the same style of arguments that printf(3) does. 82 | */ 83 | void bgpcorsaro_log_file(const char *func, iow_t *logfile, const char *format, 84 | ...) ATTR_FORMAT_PRINTF(3, 4); 85 | 86 | /** Initialize the logging sub-system for an bgpcorsaro output object 87 | * 88 | * @param bgpcorsaro The bgpcorsaro object to associate the logger with 89 | * @return 0 if successful, -1 if an error occurs 90 | */ 91 | int bgpcorsaro_log_init(bgpcorsaro_t *bgpcorsaro); 92 | 93 | /** Close the log file for an bgpcorsaro output object 94 | * 95 | * @param bgpcorsaro The bgpcorsaro output object to close logging for 96 | */ 97 | void bgpcorsaro_log_close(bgpcorsaro_t *bgpcorsaro); 98 | 99 | #endif /* __BGPCORSARO_LOG_H */ 100 | -------------------------------------------------------------------------------- /lib/io/bsrt/libbgpcorsaro/bgpcorsaro_plugin.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | #ifndef __BGPCORSARO_PLUGIN_H 27 | #define __BGPCORSARO_PLUGIN_H 28 | 29 | #include "bgpcorsaro_int.h" 30 | 31 | /** @file 32 | * 33 | * @brief Header file dealing with the bgpcorsaro plugin manager 34 | * 35 | * @author Alistair King 36 | * 37 | */ 38 | 39 | /** The name of this plugin */ 40 | #define PLUGIN_NAME "routingtables" 41 | 42 | /** An bgpcorsaro packet processing plugin */ 43 | /* All functions should return -1, or NULL on failure */ 44 | typedef struct bgpcorsaro_plugin { 45 | // #ifdef WITH_PLUGIN_TIMING 46 | /* variables that hold timing information for this plugin */ 47 | 48 | /** Number of usec spent in the init_output function */ 49 | uint64_t init_output_usec; 50 | 51 | /** Number of usec spent in the process_packet or process_flowtuple 52 | functions */ 53 | uint64_t process_packet_usec; 54 | 55 | /** Number of usec spent in the start_interval function */ 56 | uint64_t start_interval_usec; 57 | 58 | /** Number of usec spent in the end_interval function */ 59 | uint64_t end_interval_usec; 60 | // #endif 61 | 62 | } bgpcorsaro_plugin_t; 63 | 64 | extern bgpcorsaro_plugin_t bgpcorsaro_routingtables_plugin; 65 | 66 | #endif /* __BGPCORSARO_PLUGIN_H */ 67 | -------------------------------------------------------------------------------- /lib/io/bsrt/libbgpcorsaro/plugins/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2014 The Regents of the University of California. 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions are met: 6 | # 7 | # 1. Redistributions of source code must retain the above copyright notice, 8 | # this list of conditions and the following disclaimer. 9 | # 10 | # 2. Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | # POSSIBILITY OF SUCH DAMAGE. 25 | # 26 | 27 | SUBDIRS = libroutingtables 28 | 29 | AM_CPPFLAGS = -I$(top_srcdir) \ 30 | -I$(top_srcdir)/lib \ 31 | -I$(top_srcdir)/common 32 | 33 | noinst_LTLIBRARIES = libbgpcorsaroplugins.la 34 | 35 | include_HEADERS = 36 | PLUGIN_SRC= 37 | PLUGIN_LIBS= 38 | 39 | PLUGIN_LIBS += $(top_builddir)/lib/io/bsrt/libbgpcorsaro/plugins/libroutingtables/libroutingtables.la 40 | AM_CPPFLAGS += -I$(top_srcdir)/lib/io/bsrt/libbgpcorsaro 41 | AM_CPPFLAGS += -I$(top_srcdir)/lib/io/bsrt/libbgpcorsaro/plugins/libroutingtables 42 | PLUGIN_SRC+=bgpcorsaro_routingtables.c bgpcorsaro_routingtables.h 43 | 44 | libbgpcorsaroplugins_la_SOURCES = \ 45 | $(PLUGIN_SRC) 46 | 47 | libbgpcorsaroplugins_la_LIBADD = \ 48 | $(PLUGIN_LIBS) 49 | 50 | ACLOCAL_AMFLAGS = -I m4 51 | 52 | CLEANFILES = *~ 53 | -------------------------------------------------------------------------------- /lib/io/bsrt/libbgpcorsaro/plugins/bgpcorsaro_routingtables.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | #ifndef __BGPCORSARO_ROUTINGTABLES_H 27 | #define __BGPCORSARO_ROUTINGTABLES_H 28 | 29 | #include "bgpcorsaro_plugin.h" 30 | 31 | /** @file 32 | * 33 | * @brief Header file which exports bgpcorsaro_stats plugin API 34 | * 35 | * @author Chiara Orsini 36 | * 37 | */ 38 | 39 | int bgpcorsaro_routingtables_init_output(struct bgpcorsaro *bgpcorsaro); 40 | int bgpcorsaro_routingtables_close_output(struct bgpcorsaro *bgpcorsaro); 41 | int bgpcorsaro_routingtables_start_interval(struct bgpcorsaro *bgpcorsaro, 42 | struct bgpcorsaro_interval *int_start); 43 | int bgpcorsaro_routingtables_end_interval(struct bgpcorsaro *bgpcorsaro, 44 | struct bgpcorsaro_interval *int_end); 45 | int bgpcorsaro_routingtables_process_record(struct bgpcorsaro *bgpcorsaro, 46 | struct bgpstream_record *bs_record); 47 | 48 | #endif /* __BGPCORSARO_ROUTINGTABLES_H */ 49 | -------------------------------------------------------------------------------- /lib/io/bsrt/libbgpcorsaro/plugins/libroutingtables/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2014 The Regents of the University of California. 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions are met: 6 | # 7 | # 1. Redistributions of source code must retain the above copyright notice, 8 | # this list of conditions and the following disclaimer. 9 | # 10 | # 2. Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | # POSSIBILITY OF SUCH DAMAGE. 25 | # 26 | 27 | AM_CPPFLAGS = -I$(top_srcdir) \ 28 | -I$(top_srcdir)/lib \ 29 | -I$(top_srcdir)/lib/io/bsrt \ 30 | -I$(top_srcdir)/common 31 | 32 | noinst_LTLIBRARIES = libroutingtables.la 33 | 34 | libroutingtables_la_SOURCES = routingtables.h \ 35 | routingtables_int.h \ 36 | routingtables.c \ 37 | routingtables_metrics.c 38 | 39 | libroutingtables_la_LIBADD = 40 | 41 | ACLOCAL_AMFLAGS = -I m4 42 | 43 | CLEANFILES = *~ 44 | 45 | -------------------------------------------------------------------------------- /lib/io/bsrt/libbgpcorsaro/plugins/libroutingtables/routingtables.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | #ifndef __ROUTINGTABLES_H 27 | #define __ROUTINGTABLES_H 28 | 29 | #include "bgpstream.h" 30 | #include "bgpview.h" 31 | #include "timeseries.h" 32 | 33 | /** 34 | * @name Public Opaque Data Structures 35 | * 36 | * @{ */ 37 | 38 | /** Opaque handle that represents a routingtables instance */ 39 | typedef struct struct_routingtables_t routingtables_t; 40 | 41 | /** @} */ 42 | 43 | /** 44 | * @name Public API Functions 45 | * 46 | * @{ */ 47 | 48 | /** Create a new routingtables instance 49 | * 50 | * @param plugin_name string representing the plugin name 51 | * @param timeseries pointer to an initialized timeseries instance 52 | * @return a pointer to a routingtables instance if successful, NULL otherwise 53 | */ 54 | routingtables_t *routingtables_create(char *plugin_name, 55 | timeseries_t *timeseries); 56 | 57 | /** Return a pointer to the view used internally in the 58 | * routingtables code 59 | * 60 | * @param rt pointer to a routingtables instance to update 61 | * @return a pointer to the internal bgpview 62 | */ 63 | bgpview_t *routingtables_get_view_ptr(routingtables_t *rt); 64 | 65 | /** Set the metric prefix to be used for when outpting the time series 66 | * variables at the end of the interval 67 | * 68 | * @param rt pointer to a routingtables instance to update 69 | * @param metric_prefix metric prefix string 70 | */ 71 | void routingtables_set_metric_prefix(routingtables_t *rt, 72 | const char *metric_prefix); 73 | 74 | /** Get the metric prefix to be used for when outpting the time series 75 | * variables at the end of the interval 76 | * 77 | * @param rt pointer to a routingtables instance to update 78 | * @return the current metric prefix string, NULL if an error occurred. 79 | */ 80 | char *routingtables_get_metric_prefix(routingtables_t *rt); 81 | 82 | /** turn off metric output */ 83 | void routingtables_turn_metric_output_off(routingtables_t *rt); 84 | 85 | /** Receive the beginning of interval signal 86 | * 87 | * @param rt pointer to a routingtables instance to update 88 | * @param start_time start of the interval in epoch time (bgp time) 89 | * @return 0 if the signal was processed correctly, <0 if an error occurred. 90 | */ 91 | int routingtables_interval_start(routingtables_t *rt, int start_time); 92 | 93 | /** Receive the end of interval signal (and trigger the output of 94 | * statistics as well as the transmission of bgp views to the bgpview 95 | * if the transmission is activated) 96 | * 97 | * @param rt pointer to a routingtables instance to update 98 | * @param end_time end of the interval in epoch time (bgp time) 99 | * @return 0 if the signal was processed correctly, <0 if an error occurred. 100 | */ 101 | int routingtables_interval_end(routingtables_t *rt, int end_time); 102 | 103 | /** Process the bgpstream record, i.e. use the information contained in the 104 | * bgpstream record to update the current routing tables 105 | * 106 | * @param rt pointer to a routingtables instance to update 107 | * @param record pointer to a bgpstream record instance 108 | * @return 0 if the record was processed correctly, <0 if an error occurred. 109 | */ 110 | int routingtables_process_record(routingtables_t *rt, 111 | bgpstream_record_t *record); 112 | 113 | /** Destroy the given routingtables instance 114 | * 115 | * @param rt pointer to a routingtables instance to destroy 116 | */ 117 | void routingtables_destroy(routingtables_t *rt); 118 | 119 | /** @} */ 120 | 121 | #endif /* __ROUTINGTABLES_H */ 122 | -------------------------------------------------------------------------------- /lib/io/file/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2014 The Regents of the University of California. 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions are met: 6 | # 7 | # 1. Redistributions of source code must retain the above copyright notice, 8 | # this list of conditions and the following disclaimer. 9 | # 10 | # 2. Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | # POSSIBILITY OF SUCH DAMAGE. 25 | # 26 | 27 | SUBDIRS = 28 | 29 | AM_CPPFLAGS = -I$(top_srcdir) \ 30 | -I$(top_srcdir)/common \ 31 | -I$(top_srcdir)/lib \ 32 | -I$(top_srcdir)/lib/io 33 | 34 | noinst_LTLIBRARIES = libbgpview_io_file.la 35 | 36 | include_HEADERS = 37 | 38 | libbgpview_io_file_la_SOURCES = \ 39 | bgpview_io_file.c \ 40 | bgpview_io_file.h 41 | 42 | libbgpview_io_file_la_LIBADD = 43 | 44 | 45 | ACLOCAL_AMFLAGS = -I m4 46 | 47 | CLEANFILES = *~ 48 | -------------------------------------------------------------------------------- /lib/io/file/bgpview_io_file.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef __BGPVIEW_IO_FILE_H 28 | #define __BGPVIEW_IO_FILE_H 29 | 30 | #include "bgpview.h" 31 | #include "bgpview_io.h" 32 | #include 33 | 34 | /** Write the given view to the given file (in binary format) 35 | * 36 | * @param outfile wandio file handle to write to 37 | * @param view pointer to the view to send 38 | * @param cb callback function to use to filter entries (may be NULL) 39 | * @param cb_user user pointer provided to callback function 40 | * @return 0 if the view was written successfully, -1 otherwise 41 | */ 42 | int bgpview_io_file_write(iow_t *outfile, bgpview_t *view, 43 | bgpview_io_filter_cb_t *cb, void *cb_user); 44 | 45 | /** Receive a view from the given file 46 | * 47 | * @param infile wandio file handle to read from 48 | * @param view pointer to the clear/new view to receive into 49 | * @param cb callback function to use to filter entries (may be NULL) 50 | * @return 1 if a view was successfully read, 0 if EOF was reached, -1 if an 51 | * error occurred 52 | */ 53 | int bgpview_io_file_read(io_t *infile, bgpview_t *view, 54 | bgpview_io_filter_peer_cb_t *peer_cb, 55 | bgpview_io_filter_pfx_cb_t *pfx_cb, 56 | bgpview_io_filter_pfx_peer_cb_t *pfx_peer_cb); 57 | 58 | /** Print the given view to the given file (in ASCII format) 59 | * 60 | * @param outfile wandio file handle to print to 61 | * @param view pointer to the view to output 62 | * @return 0 if the view was output successfully, -1 otherwise 63 | */ 64 | int bgpview_io_file_print(iow_t *outfile, bgpview_t *view); 65 | 66 | /** Dump the given BGP View to stdout 67 | * 68 | * @param view pointer to a view structure 69 | */ 70 | void bgpview_io_file_dump(bgpview_t *view); 71 | 72 | #endif /* __BGPVIEW_IO_FILE_H */ 73 | -------------------------------------------------------------------------------- /lib/io/kafka/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2014 The Regents of the University of California. 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions are met: 6 | # 7 | # 1. Redistributions of source code must retain the above copyright notice, 8 | # this list of conditions and the following disclaimer. 9 | # 10 | # 2. Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | # POSSIBILITY OF SUCH DAMAGE. 25 | # 26 | 27 | SUBDIRS = 28 | 29 | AM_CPPFLAGS = -I$(top_srcdir) \ 30 | -I$(top_srcdir)/common \ 31 | -I$(top_srcdir)/lib \ 32 | -I$(top_srcdir)/lib/io 33 | 34 | noinst_LTLIBRARIES = libbgpview_io_kafka.la 35 | 36 | include_HEADERS = 37 | 38 | libbgpview_io_kafka_la_SOURCES = \ 39 | bgpview_io_kafka.c \ 40 | bgpview_io_kafka.h \ 41 | bgpview_io_kafka_int.h \ 42 | bgpview_io_kafka_producer.c \ 43 | bgpview_io_kafka_consumer.c 44 | 45 | libbgpview_io_kafka_la_LIBADD = 46 | 47 | 48 | ACLOCAL_AMFLAGS = -I m4 49 | 50 | CLEANFILES = *~ 51 | -------------------------------------------------------------------------------- /lib/io/test/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2014 The Regents of the University of California. 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions are met: 6 | # 7 | # 1. Redistributions of source code must retain the above copyright notice, 8 | # this list of conditions and the following disclaimer. 9 | # 10 | # 2. Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | # POSSIBILITY OF SUCH DAMAGE. 25 | # 26 | 27 | SUBDIRS = 28 | 29 | AM_CPPFLAGS = -I$(top_srcdir) \ 30 | -I$(top_srcdir)/common \ 31 | -I$(top_srcdir)/lib \ 32 | -I$(top_srcdir)/lib/io 33 | 34 | noinst_LTLIBRARIES = libbgpview_io_test.la 35 | 36 | include_HEADERS = 37 | 38 | libbgpview_io_test_la_SOURCES = \ 39 | bgpview_io_test.c \ 40 | bgpview_io_test.h 41 | 42 | libbgpview_io_test_la_LIBADD = 43 | 44 | 45 | ACLOCAL_AMFLAGS = -I m4 46 | 47 | CLEANFILES = *~ 48 | -------------------------------------------------------------------------------- /lib/io/test/bgpview_io_test.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef __BGPVIEW_IO_TEST_H 28 | #define __BGPVIEW_IO_TEST_H 29 | 30 | #include "bgpview.h" 31 | 32 | typedef struct bgpview_io_test bgpview_io_test_t; 33 | 34 | /** Create a test generator instance */ 35 | bgpview_io_test_t *bgpview_io_test_create(const char *opts); 36 | 37 | /** Destroy the given test generator instance */ 38 | void bgpview_io_test_destroy(bgpview_io_test_t *generator); 39 | 40 | /** Generate a semi-random view */ 41 | int bgpview_io_test_generate_view(bgpview_io_test_t *generator, 42 | bgpview_t *view); 43 | 44 | #endif /* __BGPVIEW_IO_TEST_H */ 45 | -------------------------------------------------------------------------------- /lib/io/zmq/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2014 The Regents of the University of California. 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions are met: 6 | # 7 | # 1. Redistributions of source code must retain the above copyright notice, 8 | # this list of conditions and the following disclaimer. 9 | # 10 | # 2. Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | # POSSIBILITY OF SUCH DAMAGE. 25 | # 26 | 27 | SUBDIRS = 28 | 29 | AM_CPPFLAGS = -I$(top_srcdir) \ 30 | -I$(top_srcdir)/common \ 31 | -I$(top_srcdir)/lib \ 32 | -I$(top_srcdir)/lib/io 33 | 34 | noinst_LTLIBRARIES = libbgpview_io_zmq.la 35 | 36 | include_HEADERS = \ 37 | bgpview_io_zmq.h \ 38 | bgpview_io_zmq_client.h \ 39 | bgpview_io_zmq_server.h 40 | 41 | libbgpview_io_zmq_la_SOURCES = \ 42 | bgpview_io_zmq_client.h \ 43 | bgpview_io_zmq_client_int.h \ 44 | bgpview_io_zmq_client.c \ 45 | bgpview_io_zmq_client_broker.h \ 46 | bgpview_io_zmq_client_broker.c \ 47 | bgpview_io_zmq_server.h \ 48 | bgpview_io_zmq_server_int.h \ 49 | bgpview_io_zmq_server.c \ 50 | bgpview_io_zmq_store.h \ 51 | bgpview_io_zmq_store.c \ 52 | bgpview_io_zmq_int.h \ 53 | bgpview_io_zmq.c \ 54 | bgpview_io_zmq.h 55 | 56 | libbgpview_io_zmq_la_LIBADD = 57 | 58 | 59 | ACLOCAL_AMFLAGS = -I m4 60 | 61 | CLEANFILES = *~ 62 | -------------------------------------------------------------------------------- /lib/io/zmq/bgpview_io_zmq.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef __BGPVIEW_IO_ZMQ_H 28 | #define __BGPVIEW_IO_ZMQ_H 29 | 30 | #include 31 | 32 | /** @file 33 | * 34 | * @brief Header file that exposes both bgpview_io_zmq_client and 35 | * bgpview_io_zmq_server. 36 | * 37 | * @author Alistair King 38 | * 39 | */ 40 | 41 | /** 42 | * @name Public Constants 43 | * 44 | * @{ */ 45 | 46 | /** Default URI for the server to listen for client requests on */ 47 | #define BGPVIEW_IO_ZMQ_CLIENT_URI_DEFAULT "tcp://*:6300" 48 | 49 | /** Default URI for the server to publish tables on (subscribed to by consumer 50 | clients) */ 51 | #define BGPVIEW_IO_ZMQ_CLIENT_PUB_URI_DEFAULT "tcp://*:6301" 52 | 53 | /** Default the server/client heartbeat interval to 2000 msec */ 54 | #define BGPVIEW_IO_ZMQ_HEARTBEAT_INTERVAL_DEFAULT 2000 55 | 56 | /** Default the server/client heartbeat liveness to 450 beats (15min) */ 57 | #define BGPVIEW_IO_ZMQ_HEARTBEAT_LIVENESS_DEFAULT 450 58 | 59 | /** Default the client reconnect minimum interval to 1 second */ 60 | #define BGPVIEW_IO_ZMQ_RECONNECT_INTERVAL_MIN 1000 61 | 62 | /** Default the client reconnect maximum interval to 32 seconds */ 63 | #define BGPVIEW_IO_ZMQ_RECONNECT_INTERVAL_MAX 32000 64 | 65 | /** @} */ 66 | 67 | /** 68 | * @name Public Opaque Data Structures 69 | * 70 | * @{ */ 71 | 72 | /** @} */ 73 | 74 | /** 75 | * @name Public Data Structures 76 | * 77 | * @{ */ 78 | 79 | /** Type of a sequence number */ 80 | typedef uint32_t seq_num_t; 81 | 82 | /** @} */ 83 | 84 | /** 85 | * @name Public Enums 86 | * 87 | * @{ */ 88 | 89 | /** Producer Intents 90 | * 91 | * A producer has intents: it intends to send messages about something. E.g. a 92 | * new prefix table. 93 | */ 94 | typedef enum { 95 | 96 | /** Prefix Table */ 97 | BGPVIEW_PRODUCER_INTENT_PREFIX = 0x01, 98 | 99 | } bgpview_producer_intent_t; 100 | 101 | #include "bgpview_io_zmq_client.h" 102 | #include "bgpview_io_zmq_server.h" 103 | 104 | #endif /* __BGPVIEW_IO_ZMQ_H */ 105 | -------------------------------------------------------------------------------- /lib/io/zmq/bgpview_io_zmq_client_broker.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef __BGPVIEW_IO_ZMQ_CLIENT_BROKER_H 28 | #define __BGPVIEW_IO_ZMQ_CLIENT_BROKER_H 29 | 30 | #include "bgpview_io_zmq_int.h" 31 | #include "khash.h" 32 | #include 33 | #include 34 | 35 | /** @file 36 | * 37 | * @brief Header file that exposes the private interface of the bgpview 38 | * client broker 39 | * 40 | * @author Alistair King 41 | * 42 | */ 43 | 44 | /** The maximum number of requests that we allow to be outstanding at any time 45 | */ 46 | #define MAX_OUTSTANDING_REQ 2 47 | 48 | /** The number of frames that we allocate each time we need more messages */ 49 | #define BGPVIEW_IO_ZMQ_CLIENT_BROKER_REQ_MSG_FRAME_CHUNK 256000 50 | 51 | /** The maximum number of messages that we receive from the server before 52 | yielding back to the reactor */ 53 | #define BGPVIEW_IO_ZMQ_CLIENT_BROKER_GREEDY_MAX_MSG 10 54 | 55 | /** 56 | * @name Public Enums 57 | * 58 | * @{ */ 59 | 60 | /** @} */ 61 | 62 | /** 63 | * @name Public Opaque Data Structures 64 | * 65 | * @{ */ 66 | 67 | /** @} */ 68 | 69 | /** 70 | * @name Public Data Structures 71 | * 72 | * @{ */ 73 | 74 | /** Holds information about a single outstanding request sent to the server */ 75 | typedef struct bgpview_io_zmq_client_broker_req { 76 | 77 | /** Is this request in use? */ 78 | int in_use; 79 | 80 | /** Message type in the request (and reply) */ 81 | bgpview_io_zmq_msg_type_t msg_type; 82 | 83 | /** The sequence number in the request (used to match replies) */ 84 | seq_num_t seq_num; 85 | 86 | /** The time that this request should next be retried */ 87 | uint64_t retry_at; 88 | 89 | /** The number of retries that remain */ 90 | uint8_t retries_remaining; 91 | 92 | /** Messages to send to the server */ 93 | zmq_msg_t *msg_frames; 94 | 95 | /** Number of used msg frames */ 96 | int msg_frames_cnt; 97 | 98 | /** Number of allocated msg frames */ 99 | int msg_frames_alloc; 100 | 101 | } bgpview_io_zmq_client_broker_req_t; 102 | 103 | /** Config for the broker. Populated by the client */ 104 | typedef struct bgpview_io_zmq_client_broker_config { 105 | 106 | /** set of bgpview_producer_intent_t flags */ 107 | uint8_t intents; 108 | 109 | /** Pointer to the master's state (passed to callbacks) */ 110 | struct bgpview_io_zmq_client *master; 111 | 112 | /** 0MQ context pointer (for broker->server comms) */ 113 | zctx_t *ctx; 114 | 115 | /** URI to connect to the server on */ 116 | char *server_uri; 117 | 118 | /** URI to subscribe to server table messages on */ 119 | char *server_sub_uri; 120 | 121 | /** Time (in ms) between heartbeats sent to the server */ 122 | uint64_t heartbeat_interval; 123 | 124 | /** The number of heartbeats that can go by before the server is declared 125 | dead */ 126 | int heartbeat_liveness; 127 | 128 | /** The minimum time (in ms) after a server disconnect before we try to 129 | reconnect */ 130 | uint64_t reconnect_interval_min; 131 | 132 | /** The maximum time (in ms) after a server disconnect before we try to 133 | reconnect (after exponential back-off) */ 134 | uint64_t reconnect_interval_max; 135 | 136 | /** The time that we will linger once a shutdown request has been received */ 137 | uint64_t shutdown_linger; 138 | 139 | /** Request timeout in msec */ 140 | uint64_t request_timeout; 141 | 142 | /** Request retries */ 143 | int request_retries; 144 | 145 | /** Set if the broker is in an error state */ 146 | int err; 147 | 148 | /** Identity of this client. MUST be globally unique. If this field is set 149 | * when the broker is started, it will be used to set the identity of the zmq 150 | * socket 151 | */ 152 | char *identity; 153 | 154 | /** Pointer to the pipe used to talk to the master */ 155 | zsock_t *master_pipe; 156 | 157 | } bgpview_io_zmq_client_broker_config_t; 158 | 159 | /** State for a broker instance */ 160 | typedef struct bgpview_io_zmq_client_broker { 161 | 162 | /** Pointer to the config info that our master prepared for us (READ-ONLY) */ 163 | bgpview_io_zmq_client_broker_config_t *cfg; 164 | 165 | /** Pointer to the pipe used to get/send signals to/from the master */ 166 | zsock_t *signal_pipe; 167 | 168 | /** Pointer to the pipe used to talk to the master */ 169 | zsock_t *master_pipe; 170 | 171 | /** Pointer to the resolved zmq socket used to talk to the master */ 172 | void *master_zocket; 173 | 174 | /** Has the master pipe been removed from the reactor? */ 175 | int master_removed; 176 | 177 | /** Socket used to connect to the server */ 178 | void *server_socket; 179 | 180 | /** Socket used to receive server table messages (for consumers) */ 181 | void *server_sub_socket; 182 | 183 | /** Ordered list of outstanding requests (used for re-transmits) */ 184 | bgpview_io_zmq_client_broker_req_t req_list[MAX_OUTSTANDING_REQ]; 185 | 186 | /** Number of currently outstanding requests (<= MAX_OUTSTANDING_REQ) */ 187 | int req_count; 188 | 189 | /** Time (in ms) to send the next heartbeat to server */ 190 | uint64_t heartbeat_next; 191 | 192 | /** The number of beats before the server is declared dead */ 193 | int heartbeat_liveness_remaining; 194 | 195 | /** The time before we will next attempt to reconnect */ 196 | uint64_t reconnect_interval_next; 197 | 198 | /** Indicates the time that the broker must shut down by (calculated as 199 | $TERM.time + shutdown_linger) */ 200 | uint64_t shutdown_time; 201 | 202 | /** Event loop */ 203 | zloop_t *loop; 204 | 205 | /** Heartbeat timer ID */ 206 | int timer_id; 207 | 208 | } bgpview_io_zmq_client_broker_t; 209 | 210 | /** @} */ 211 | 212 | /** Main event loop of the client broker. Conforms to the zactor_fn spec. 213 | * 214 | * @param pipe pointer to a pipe used to communicate with the client 215 | * @param args pointer to a pre-populated client broker state struct 216 | * 217 | * @note all communication with the broker must be through the pipe. NO shared 218 | * memory is to be used. 219 | */ 220 | void bgpview_io_zmq_client_broker_run(zsock_t *pipe, void *args); 221 | 222 | /** Initialize a request instance 223 | * 224 | * @return pointer to a request instance if successful, NULL otherwise 225 | */ 226 | bgpview_io_zmq_client_broker_req_t *bgpview_io_zmq_client_broker_req_init(); 227 | 228 | /** Free a request instance 229 | * 230 | * @param req_p double-pointer to a request instance 231 | */ 232 | void bgpview_io_zmq_client_broker_req_free( 233 | bgpview_io_zmq_client_broker_req_t **req_p); 234 | 235 | #endif 236 | -------------------------------------------------------------------------------- /lib/io/zmq/bgpview_io_zmq_client_int.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef __BGPVIEW_IO_ZMQ_CLIENT_INT_H 28 | #define __BGPVIEW_IO_ZMQ_CLIENT_INT_H 29 | 30 | #include 31 | #include 32 | 33 | #include "bgpview_io_zmq_client.h" 34 | #include "bgpview_io_zmq_client_broker.h" 35 | 36 | /** @file 37 | * 38 | * @brief Header file that exposes the private interface of the bgpview 39 | * client 40 | * 41 | * @author Alistair King 42 | * 43 | */ 44 | 45 | /** 46 | * @name Public Opaque Data Structures 47 | * 48 | * @{ */ 49 | 50 | /** @} */ 51 | 52 | /** 53 | * @name Protected Data Structures 54 | * 55 | * @{ */ 56 | 57 | struct bgpview_io_zmq_client { 58 | 59 | /** shared config that we have prepared for our broker(s) */ 60 | bgpview_io_zmq_client_broker_config_t broker_config; 61 | 62 | /** handle to communicate with our broker */ 63 | zactor_t *broker; 64 | 65 | /** Socket to communicate data with the broker */ 66 | zsock_t *broker_sock; 67 | 68 | /** raw socket to the broker */ 69 | void *broker_zocket; 70 | 71 | /** Next request sequence number to use */ 72 | seq_num_t seq_num; 73 | 74 | /** Indicates that the client has been signaled to shutdown */ 75 | int shutdown; 76 | }; 77 | 78 | /** @} */ 79 | 80 | /** 81 | * @name Public Enums 82 | * 83 | * @{ */ 84 | 85 | /** @} */ 86 | 87 | #endif /* __BGPVIEW_IO_ZMQ_CLIENT_INT_H */ 88 | -------------------------------------------------------------------------------- /lib/io/zmq/bgpview_io_zmq_int.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef __BGPVIEW_IO_ZMQ_INT_H 28 | #define __BGPVIEW_IO_ZMQ_INT_H 29 | 30 | #include "bgpview_io_zmq.h" 31 | 32 | /** 33 | * @name Private Constants 34 | * 35 | * @{ */ 36 | 37 | #ifdef DEBUG_TIMING 38 | 39 | #define TIMER_START(timer) \ 40 | struct timeval timer##_start; \ 41 | do { \ 42 | gettimeofday_wrap(&timer##_start); \ 43 | } while (0) 44 | 45 | #define TIMER_END(timer) \ 46 | struct timeval timer##_end, timer##_diff; \ 47 | do { \ 48 | gettimeofday_wrap(&timer##_end); \ 49 | timeval_subtract(&timer##_diff, &timer##_end, &timer##_start); \ 50 | } while (0) 51 | 52 | #define TIMER_VAL(timer) \ 53 | ((timer##_diff.tv_sec * 1000000) + timer##_diff.tv_usec) 54 | #else 55 | 56 | #define TIMER_START(timer) 57 | #define TIMER_END(timer) 58 | #define TIMER_VAL(timer) (uint64_t)(0) 59 | 60 | #endif 61 | 62 | #define BW_PFX_ROW_BUFFER_LEN 17 + (BGPVIEW_PEER_MAX_CNT * 5) 63 | 64 | /* shared constants are in bgpview_io_zmq.h */ 65 | 66 | /** @} */ 67 | 68 | /** 69 | * @name Private Enums 70 | * 71 | * @{ */ 72 | 73 | /** Enumeration of message types 74 | * 75 | * @note these will be cast to a uint8_t, so be sure that there are fewer than 76 | * 2^8 values 77 | */ 78 | typedef enum { 79 | /** Invalid message */ 80 | BGPVIEW_IO_ZMQ_MSG_TYPE_UNKNOWN = 0, 81 | 82 | /** Client is ready to send requests/Server is ready for requests */ 83 | BGPVIEW_IO_ZMQ_MSG_TYPE_READY = 1, 84 | 85 | /** Client is explicitly disconnecting (clean shutdown) */ 86 | BGPVIEW_IO_ZMQ_MSG_TYPE_TERM = 2, 87 | 88 | /** Server/Client is still alive */ 89 | BGPVIEW_IO_ZMQ_MSG_TYPE_HEARTBEAT = 3, 90 | 91 | /** A view for the server to process */ 92 | BGPVIEW_IO_ZMQ_MSG_TYPE_VIEW = 4, 93 | 94 | /** Server is sending a response to a client */ 95 | BGPVIEW_IO_ZMQ_MSG_TYPE_REPLY = 5, 96 | 97 | /** Highest message number in use */ 98 | BGPVIEW_IO_ZMQ_MSG_TYPE_MAX = BGPVIEW_IO_ZMQ_MSG_TYPE_REPLY, 99 | 100 | } bgpview_io_zmq_msg_type_t; 101 | 102 | #define bgpview_io_zmq_msg_type_size_t sizeof(uint8_t) 103 | 104 | /** @} */ 105 | 106 | /* ========== MESSAGE TYPES ========== */ 107 | 108 | /** Receives one message from the given socket and decodes as a message type 109 | * 110 | * @param src socket to receive on 111 | * @param flags flags passed directed to zmq_recv (e.g. ZMQ_DONTWAIT) 112 | * @return the type of the message, or BGPVIEW_MSG_TYPE_UNKNOWN 113 | */ 114 | bgpview_io_zmq_msg_type_t bgpview_io_zmq_recv_type(void *src, int flags); 115 | 116 | /* ========== VIEW IO ========== */ 117 | 118 | /** Send the given view to the given socket 119 | * 120 | * @param dest socket to send the view to 121 | * @param view pointer to the view to send 122 | * @param cb callback function to use to filter entries (may be NULL) 123 | * @return 0 if the view was sent successfully, -1 otherwise 124 | */ 125 | int bgpview_io_zmq_send(void *dest, bgpview_t *view, bgpview_io_filter_cb_t *cb, 126 | void *cb_user); 127 | 128 | /** Receive a view from the given socket 129 | * 130 | * @param src socket to receive on 131 | * @param view pointer to the clear/new view to receive into 132 | * @param cb callback function to use to filter entries (may be NULL) 133 | * @return pointer to the view instance received, NULL if an error occurred. 134 | */ 135 | int bgpview_io_zmq_recv(void *src, bgpview_t *view, 136 | bgpview_io_filter_peer_cb_t *peer_cb, 137 | bgpview_io_filter_pfx_cb_t *pfx_cb, 138 | bgpview_io_filter_pfx_peer_cb_t *pfx_peer_cb); 139 | 140 | #endif /* __BGPVIEW_IO_ZMQ_H */ 141 | -------------------------------------------------------------------------------- /lib/io/zmq/bgpview_io_zmq_server.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef __BGPVIEW_IO_ZMQ_SERVER_H 28 | #define __BGPVIEW_IO_ZMQ_SERVER_H 29 | 30 | #include 31 | #include 32 | 33 | /** @file 34 | * 35 | * @brief Header file that exposes the public interface of the bgpview 36 | * server. 37 | * 38 | * @author Alistair King 39 | * 40 | */ 41 | 42 | /** 43 | * @name Public Constants 44 | * 45 | * @{ */ 46 | 47 | /* shared constants are in bgpview_io_zmq.h */ 48 | 49 | /** The default number of views in the window */ 50 | #define BGPVIEW_IO_ZMQ_SERVER_WINDOW_LEN 6 51 | 52 | /** Maximum length of the metric prefix string */ 53 | #define BGPVIEW_IO_ZMQ_SERVER_METRIC_PREFIX_LEN 1024 54 | 55 | /** Default value of the metric prefix string */ 56 | #define BGPVIEW_IO_ZMQ_SERVER_METRIC_PREFIX_DEFAULT "bgp" 57 | 58 | /** @} */ 59 | 60 | /** 61 | * @name Public Enums 62 | * 63 | * @{ */ 64 | 65 | /** @} */ 66 | 67 | /** 68 | * @name Public Opaque Data Structures 69 | * 70 | * @{ */ 71 | 72 | typedef struct bgpview_io_zmq_server bgpview_io_zmq_server_t; 73 | 74 | /** @} */ 75 | 76 | /** 77 | * @name Public Data Structures 78 | * 79 | * @{ */ 80 | 81 | /** Public information about a client given to bgpview when a client connects 82 | * or disconnects 83 | */ 84 | typedef struct bgpview_io_zmq_server_client_info { 85 | /** Client name */ 86 | char *name; 87 | 88 | /** Producer Intents (bgpview_consumer_intent_t flags) */ 89 | uint8_t intents; 90 | 91 | } bgpview_io_zmq_server_client_info_t; 92 | 93 | /** @} */ 94 | 95 | /** Initialize a new BGPView Server instance 96 | * 97 | * @return a pointer to a bgpview server instance if successful, NULL if an 98 | * error occurred. 99 | */ 100 | bgpview_io_zmq_server_t *bgpview_io_zmq_server_init(); 101 | 102 | /** Set bgpview prefix metric 103 | * 104 | * @param server pointer to a bgpview server instance 105 | * @param metric_prefix string that represents the prefix to prepend to metrics 106 | */ 107 | void bgpview_io_zmq_server_set_metric_prefix(bgpview_io_zmq_server_t *server, 108 | char *metric_prefix); 109 | 110 | /** Start the given bgpview server instance 111 | * 112 | * @param server pointer to a bgpview server instance to start 113 | * @return 0 if the server started successfully, -1 otherwise. 114 | * 115 | * This function will block and run until the server is stopped. 116 | */ 117 | int bgpview_io_zmq_server_start(bgpview_io_zmq_server_t *server); 118 | 119 | /** Stop the given bgpview server instance at the next safe occasion. 120 | * 121 | * This is useful to initiate a clean shutdown if you are handling signals in 122 | * bgpview. Call this from within your signal handler. It should also be 123 | * called from bgpview_stop to pass the signal through. 124 | * 125 | * @param server pointer to the bgpview instance to stop 126 | */ 127 | void bgpview_io_zmq_server_stop(bgpview_io_zmq_server_t *server); 128 | 129 | /** Free the given bgpview server instance 130 | * 131 | * @param server pointer to the bgpview server instance to free 132 | */ 133 | void bgpview_io_zmq_server_free(bgpview_io_zmq_server_t *server); 134 | 135 | /** Set the size of the view window 136 | * 137 | * @param pointer to a bgpview server instance to configure 138 | * @param length of the view window (in number of views) 139 | */ 140 | void bgpview_io_zmq_server_set_window_len(bgpview_io_zmq_server_t *server, 141 | int window_len); 142 | 143 | /** Set the URI for the server to listen for client connections on 144 | * 145 | * @param server pointer to a bgpview server instance to update 146 | * @param uri pointer to a uri string 147 | * @return 0 if the uri was set successfully, -1 otherwise 148 | * 149 | * @note defaults to BGPVIEW_IO_ZMQ_CLIENT_URI_DEFAULT 150 | */ 151 | int bgpview_io_zmq_server_set_client_uri(bgpview_io_zmq_server_t *server, 152 | const char *uri); 153 | 154 | /** Set the URI for the server to publish tables on 155 | * (subscribed to by consumer clients) 156 | * 157 | * @param server pointer to a bgpview server instance to update 158 | * @param uri pointer to a uri string 159 | * @return 0 if the uri was set successfully, -1 otherwise 160 | * 161 | * @note defaults to BGPVIEW_IO_ZMQ_CLIENT_PUB_URI_DEFAULT 162 | */ 163 | int bgpview_io_zmq_server_set_client_pub_uri(bgpview_io_zmq_server_t *server, 164 | const char *uri); 165 | 166 | /** Set the heartbeat interval 167 | * 168 | * @param server pointer to a bgpview server instance to update 169 | * @param interval_ms time in ms between heartbeats 170 | * 171 | * @note defaults to BGPVIEW_IO_ZMQ_HEARTBEAT_INTERVAL_DEFAULT 172 | */ 173 | void bgpview_io_zmq_server_set_heartbeat_interval( 174 | bgpview_io_zmq_server_t *server, uint64_t interval_ms); 175 | 176 | /** Set the heartbeat liveness 177 | * 178 | * @param server pointer to a bgpview server instance to update 179 | * @param beats number of heartbeats that can go by before a server is 180 | * declared dead 181 | * 182 | * @note defaults to BGPVIEW_IO_ZMQ_HEARTBEAT_LIVENESS_DEFAULT 183 | */ 184 | void bgpview_io_zmq_server_set_heartbeat_liveness( 185 | bgpview_io_zmq_server_t *server, int beats); 186 | 187 | #endif 188 | -------------------------------------------------------------------------------- /lib/io/zmq/bgpview_io_zmq_server_int.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef __BGPVIEW_IO_ZMQ_SERVER_INT_H 28 | #define __BGPVIEW_IO_ZMQ_SERVER_INT_H 29 | 30 | #include "bgpview.h" 31 | #include "bgpview_io_zmq_server.h" 32 | #include "bgpview_io_zmq_store.h" 33 | #include "khash.h" 34 | #include 35 | #include 36 | 37 | /** @file 38 | * 39 | * @brief Header file that exposes the (protected) interface of the bgpview 40 | * server. This interface is only used by bgpview 41 | * 42 | * @author Alistair King 43 | * 44 | */ 45 | 46 | /** 47 | * @name Public Constants 48 | * 49 | * @{ */ 50 | 51 | /* shared constants are in bgpview_io_zmq.h */ 52 | 53 | /** @} */ 54 | 55 | /** 56 | * @name Public Enums 57 | * 58 | * @{ */ 59 | 60 | /** @} */ 61 | 62 | /** 63 | * @name Public Opaque Data Structures 64 | * 65 | * @{ */ 66 | 67 | /** @} */ 68 | 69 | /** 70 | * @name Public Data Structures 71 | * 72 | * @{ */ 73 | 74 | /** Protected information about a client used to handle client connections */ 75 | typedef struct bgpview_io_zmq_server_client { 76 | 77 | /** Identity frame data that the client sent us */ 78 | zmq_msg_t identity; 79 | 80 | /** Hex id of the client (may be the same as the printable ID */ 81 | char *hexid; 82 | 83 | /** Printable ID of client (for debugging and logging) */ 84 | char *id; 85 | 86 | /** Time at which the client expires */ 87 | uint64_t expiry; 88 | 89 | /** info about this client that we will send to the client connect handler */ 90 | bgpview_io_zmq_server_client_info_t info; 91 | 92 | } bgpview_io_zmq_server_client_t; 93 | 94 | KHASH_INIT(strclient, char *, bgpview_io_zmq_server_client_t *, 1, 95 | kh_str_hash_func, kh_str_hash_equal); 96 | 97 | struct bgpview_io_zmq_server { 98 | 99 | /** Metric prefix to output metrics */ 100 | char metric_prefix[BGPVIEW_IO_ZMQ_SERVER_METRIC_PREFIX_LEN]; 101 | 102 | /** 0MQ context pointer */ 103 | zctx_t *ctx; 104 | 105 | /** URI to listen for clients on */ 106 | char *client_uri; 107 | 108 | /** URI to pub tables on */ 109 | char *client_pub_uri; 110 | 111 | /** Socket to bind to for client connections */ 112 | void *client_socket; 113 | 114 | /** Socket to pub tables on */ 115 | void *client_pub_socket; 116 | 117 | /** List of clients that are connected */ 118 | khash_t(strclient) * clients; 119 | 120 | /** Time (in ms) between heartbeats sent to clients */ 121 | uint64_t heartbeat_interval; 122 | 123 | /** Time (in ms) to send the next heartbeat to clients */ 124 | uint64_t heartbeat_next; 125 | 126 | /** The number of heartbeats that can go by before a client is declared 127 | dead */ 128 | int heartbeat_liveness; 129 | 130 | /** Indicates that the server should shutdown at the next opportunity */ 131 | int shutdown; 132 | 133 | /** Next view number */ 134 | uint64_t view_num; 135 | 136 | /** BGPView Store instance */ 137 | bgpview_io_zmq_store_t *store; 138 | 139 | /** The number of heartbeats that have gone by since the last timeout check */ 140 | int store_timeout_cnt; 141 | 142 | /** The number of views in the store */ 143 | int store_window_len; 144 | }; 145 | 146 | /** @} */ 147 | 148 | /** 149 | * @name Server Publish Functions 150 | * 151 | * @{ */ 152 | 153 | /** Publish the given BGP View to any subscribed consumers 154 | * 155 | * @param server pointer to the bgpview server instance 156 | * @param table pointer to a bgp view to publish 157 | */ 158 | int bgpview_io_zmq_server_publish_view(bgpview_io_zmq_server_t *server, 159 | bgpview_t *view); 160 | 161 | /** @} */ 162 | 163 | #endif 164 | -------------------------------------------------------------------------------- /lib/io/zmq/bgpview_io_zmq_store.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef __BGPVIEW_IO_ZMQ_STORE_H 28 | #define __BGPVIEW_IO_ZMQ_STORE_H 29 | 30 | #include "bgpstream_utils_pfx.h" 31 | #include "bgpview.h" 32 | #include "bgpview_io_zmq_server.h" 33 | 34 | /** @file 35 | * 36 | * @brief Header file that exposes the protected interface of bgpview store. 37 | * 38 | * @author Alistair King 39 | * 40 | */ 41 | 42 | /** 43 | * @name Public Opaque Data Structures 44 | * 45 | * @{ */ 46 | 47 | typedef struct bgpview_io_zmq_store bgpview_io_zmq_store_t; 48 | 49 | /** @} */ 50 | 51 | /** Create a new bgpview store instance 52 | * 53 | * @param server pointer to the bgpview server instance 54 | * @param window_len number of consecutive views in the store's window 55 | * @return a pointer to a bgpview store instance, or NULL if an error 56 | * occurred 57 | */ 58 | bgpview_io_zmq_store_t * 59 | bgpview_io_zmq_store_create(bgpview_io_zmq_server_t *server, int window_len); 60 | 61 | /** Destroy the given bgpview store instance 62 | * 63 | * @param store pointer to the store instance to destroy 64 | */ 65 | void bgpview_io_zmq_store_destroy(bgpview_io_zmq_store_t *store); 66 | 67 | /** Register a new bgpview client 68 | * 69 | * @param store pointer to a store instance 70 | * @param name string name of the client 71 | * @param intents client intents 72 | * @return 0 if successful, -1 otherwise 73 | */ 74 | int bgpview_io_zmq_store_client_connect( 75 | bgpview_io_zmq_store_t *store, bgpview_io_zmq_server_client_info_t *client); 76 | 77 | /** Deregister a bgpview client 78 | * 79 | * @param store pointer to a store instance 80 | * @param name string name of the client that disconnected 81 | * @return 0 if successful, -1 otherwise 82 | */ 83 | int bgpview_io_zmq_store_client_disconnect( 84 | bgpview_io_zmq_store_t *store, bgpview_io_zmq_server_client_info_t *client); 85 | 86 | /** Retrieve a pointer to the view that represents the given time 87 | * 88 | * @param store pointer to a store instance 89 | * @param time time of the view to retrieve 90 | * @return borrowed pointer to a view if the given time is inside the current 91 | * window, NULL if it is outside 92 | */ 93 | bgpview_t *bgpview_io_zmq_store_get_view(bgpview_io_zmq_store_t *store, 94 | uint32_t time); 95 | 96 | /** Notify the store that a view it manages has been updated with new data 97 | * 98 | * @param store pointer to a store instance 99 | * @param view pointer to the view that has been updated 100 | * @param client pointer to info about the client that sent the view 101 | * @return 0 if the view was processed successfully, -1 otherwise 102 | */ 103 | int bgpview_io_zmq_store_view_updated( 104 | bgpview_io_zmq_store_t *store, bgpview_t *view, 105 | bgpview_io_zmq_server_client_info_t *client); 106 | 107 | /** Force a timeout check on the views currently in the store 108 | * 109 | * @param store pointer to a store instance 110 | * @return 0 if successful, -1 otherwise 111 | */ 112 | int bgpview_io_zmq_store_check_timeouts(bgpview_io_zmq_store_t *store); 113 | 114 | #endif /* __BGPSTORE_LIB_H */ 115 | -------------------------------------------------------------------------------- /m4/bs_with_io_mod.m4: -------------------------------------------------------------------------------- 1 | # SYNOPSIS 2 | # 3 | # BS_WITH_IO_MOD 4 | # 5 | # LICENSE 6 | # 7 | # Copyright (C) 2014 The Regents of the University of California. 8 | # 9 | # Redistribution and use in source and binary forms, with or without 10 | # modification, are permitted provided that the following conditions are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright notice, 13 | # this list of conditions and the following disclaimer. 14 | # 15 | # 2. Redistributions in binary form must reproduce the above copyright notice, 16 | # this list of conditions and the following disclaimer in the documentation 17 | # and/or other materials provided with the distribution. 18 | # 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | # POSSIBILITY OF SUCH DAMAGE. 30 | # 31 | 32 | AC_DEFUN([BS_WITH_IO_MOD], 33 | [ 34 | AC_MSG_CHECKING([whether to build with BGPView IO module: $1]) 35 | 36 | ifelse([$3], [yes], 37 | [AC_ARG_WITH([$1-io], 38 | [AS_HELP_STRING([--without-$1-io], 39 | [build without the $1 IO module])], 40 | [with_io_$1=$with_$1_io], 41 | [with_io_$1=yes])], 42 | [AC_ARG_WITH([$1-io], 43 | [AS_HELP_STRING([--with-$1-io], 44 | [build with the $1 IO module])], 45 | [with_io_$1=$with_$1_io], 46 | [with_io_$1=no])] 47 | ) 48 | 49 | WITH_BGPVIEW_IO_$2= 50 | AS_IF([test "x$with_io_$1" != xno], 51 | [ 52 | AC_DEFINE([WITH_BGPVIEW_IO_$2],[1],[Building with $1 IO]) 53 | ]) 54 | AC_MSG_RESULT([$with_io_$1]) 55 | 56 | AM_CONDITIONAL([WITH_BGPVIEW_IO_$2], [test "x$with_io_$1" != xno]) 57 | ]) 58 | -------------------------------------------------------------------------------- /m4/disable-rpath.m4: -------------------------------------------------------------------------------- 1 | dnl file : m4/disable-rpath.m4 2 | dnl author : Boris Kolpackov 3 | dnl copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC 4 | dnl license : GNU GPL v2; see accompanying LICENSE file 5 | dnl 6 | AC_DEFUN([DISABLE_RPATH],[ 7 | 8 | AC_MSG_CHECKING([whether to use rpath]) 9 | AC_ARG_ENABLE( 10 | [rpath], 11 | [AC_HELP_STRING([--disable-rpath], [patch libtool to not use rpath])], 12 | [libtool_rpath="$enable_rpath"], 13 | [libtool_rpath="yes"]) 14 | AC_MSG_RESULT($libtool_rpath) 15 | 16 | # Patch libtool to not use rpath if requested. 17 | # 18 | AC_CONFIG_COMMANDS( 19 | [libtool-rpath-patch], 20 | [if test "$libtool_use_rpath" = "no"; then 21 | sed < libtool > libtool-2 's/^hardcode_libdir_flag_spec.*$'/'hardcode_libdir_flag_spec=" -D__LIBTOOL_NO_RPATH__ "/' 22 | mv libtool-2 libtool 23 | chmod 755 libtool 24 | fi], 25 | [libtool_use_rpath=$libtool_rpath]) 26 | ])dnl 27 | -------------------------------------------------------------------------------- /tools/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2014 The Regents of the University of California. 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions are met: 6 | # 7 | # 1. Redistributions of source code must retain the above copyright notice, 8 | # this list of conditions and the following disclaimer. 9 | # 10 | # 2. Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | # POSSIBILITY OF SUCH DAMAGE. 25 | # 26 | 27 | SUBDIRS = consumers io 28 | AM_CPPFLAGS = 29 | 30 | EXTRA_DIST = 31 | 32 | ACLOCAL_AMFLAGS = -I m4 33 | 34 | CLEANFILES = *~ 35 | -------------------------------------------------------------------------------- /tools/consumers/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2014 The Regents of the University of California. 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions are met: 6 | # 7 | # 1. Redistributions of source code must retain the above copyright notice, 8 | # this list of conditions and the following disclaimer. 9 | # 10 | # 2. Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | # POSSIBILITY OF SUCH DAMAGE. 25 | # 26 | 27 | AM_CPPFLAGS = -I$(top_srcdir) \ 28 | -I$(top_srcdir)/common \ 29 | -I$(top_srcdir)/lib \ 30 | -I$(top_srcdir)/lib/io \ 31 | -I$(top_srcdir)/lib/consumers 32 | 33 | dist_bin_SCRIPTS = 34 | 35 | bin_PROGRAMS = 36 | 37 | # obtains views from {file,test,kafka,zmq} and drives consumer plugins 38 | bin_PROGRAMS += bgpview-consumer 39 | bgpview_consumer_SOURCES = \ 40 | bgpview-consumer.c 41 | bgpview_consumer_LDADD = $(top_builddir)/lib/libbgpview.la 42 | 43 | ACLOCAL_AMFLAGS = -I m4 44 | 45 | CLEANFILES = *~ 46 | -------------------------------------------------------------------------------- /tools/io/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2014 The Regents of the University of California. 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions are met: 6 | # 7 | # 1. Redistributions of source code must retain the above copyright notice, 8 | # this list of conditions and the following disclaimer. 9 | # 10 | # 2. Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | # POSSIBILITY OF SUCH DAMAGE. 25 | # 26 | 27 | AM_CPPFLAGS = -I$(top_srcdir) \ 28 | -I$(top_srcdir)/common \ 29 | -I$(top_srcdir)/lib \ 30 | -I$(top_srcdir)/lib/io 31 | 32 | dist_bin_SCRIPTS = 33 | 34 | bin_PROGRAMS = 35 | 36 | if WITH_BGPVIEW_IO_ZMQ 37 | AM_CPPFLAGS+= -I$(top_srcdir)/lib/io/zmq 38 | # runs the bgpview server 39 | bin_PROGRAMS+=bgpview-server-zmq 40 | bgpview_server_zmq_SOURCES = \ 41 | bgpview-server-zmq.c 42 | bgpview_server_zmq_LDADD = $(top_builddir)/lib/libbgpview.la 43 | endif 44 | 45 | if WITH_BGPVIEW_IO_FILE 46 | # BGPView Cat 47 | AM_CPPFLAGS+=-I$(top_srcdir)/lib/io/file 48 | bin_PROGRAMS+=bvcat 49 | bvcat_SOURCES = \ 50 | bvcat.c 51 | bvcat_LDADD = $(top_builddir)/lib/libbgpview.la 52 | endif 53 | 54 | ACLOCAL_AMFLAGS = -I m4 55 | 56 | CLEANFILES = *~ 57 | -------------------------------------------------------------------------------- /tools/io/bgpview-server-zmq.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #include "config.h" 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include "bgpview_io_zmq.h" 37 | 38 | /** Indicates that bgpview is waiting to shutdown */ 39 | volatile sig_atomic_t bgpview_shutdown = 0; 40 | 41 | /** The number of SIGINTs to catch before aborting */ 42 | #define HARD_SHUTDOWN 3 43 | 44 | static bgpview_io_zmq_server_t *server = NULL; 45 | 46 | /** Handles SIGINT gracefully and shuts down */ 47 | static void catch_sigint(int sig) 48 | { 49 | bgpview_shutdown++; 50 | if (bgpview_shutdown == HARD_SHUTDOWN) { 51 | fprintf(stderr, "caught %d SIGINT's. shutting down NOW\n", HARD_SHUTDOWN); 52 | exit(-1); 53 | } 54 | 55 | fprintf(stderr, "caught SIGINT, shutting down at the next opportunity\n"); 56 | 57 | if (server != NULL) { 58 | bgpview_io_zmq_server_stop(server); 59 | } 60 | 61 | signal(sig, catch_sigint); 62 | } 63 | 64 | static void usage(const char *name) 65 | { 66 | fprintf( 67 | stderr, 68 | "usage: %s []\n" 69 | " -c 0MQ-style URI to listen for clients on\n" 70 | " (default: %s)\n" 71 | " -C 0MQ-style URI to publish tables on\n" 72 | " (default: %s)\n" 73 | " -i Time in ms between heartbeats to clients\n" 74 | " (default: %d)\n" 75 | " -l Number of heartbeats that can go by before \n" 76 | " a client is declared dead (default: %d)\n" 77 | " -w Number of views in the window (default: %d)\n" 78 | " -m Metric prefix (default: %s)\n", 79 | name, BGPVIEW_IO_ZMQ_CLIENT_URI_DEFAULT, 80 | BGPVIEW_IO_ZMQ_CLIENT_PUB_URI_DEFAULT, 81 | BGPVIEW_IO_ZMQ_HEARTBEAT_INTERVAL_DEFAULT, 82 | BGPVIEW_IO_ZMQ_HEARTBEAT_LIVENESS_DEFAULT, BGPVIEW_IO_ZMQ_SERVER_WINDOW_LEN, 83 | BGPVIEW_IO_ZMQ_SERVER_METRIC_PREFIX_DEFAULT); 84 | } 85 | 86 | int main(int argc, char **argv) 87 | { 88 | /* for option parsing */ 89 | int opt; 90 | int prevoptind; 91 | 92 | /* to store command line argument values */ 93 | const char *client_uri = NULL; 94 | const char *client_pub_uri = NULL; 95 | 96 | uint64_t heartbeat_interval = BGPVIEW_IO_ZMQ_HEARTBEAT_INTERVAL_DEFAULT; 97 | int heartbeat_liveness = BGPVIEW_IO_ZMQ_HEARTBEAT_LIVENESS_DEFAULT; 98 | char metric_prefix[BGPVIEW_IO_ZMQ_SERVER_METRIC_PREFIX_LEN]; 99 | 100 | strcpy(metric_prefix, BGPVIEW_IO_ZMQ_SERVER_METRIC_PREFIX_DEFAULT); 101 | 102 | int window_len = BGPVIEW_IO_ZMQ_SERVER_WINDOW_LEN; 103 | 104 | signal(SIGINT, catch_sigint); 105 | 106 | while (prevoptind = optind, 107 | (opt = getopt(argc, argv, ":c:C:i:l:w:m:v?")) >= 0) { 108 | if (optind == prevoptind + 2 && *optarg == '-') { 109 | opt = ':'; 110 | --optind; 111 | } 112 | switch (opt) { 113 | case ':': 114 | fprintf(stderr, "ERROR: Missing option argument for -%c\n", optopt); 115 | usage(argv[0]); 116 | return -1; 117 | break; 118 | 119 | case 'c': 120 | client_uri = optarg; 121 | break; 122 | 123 | case 'C': 124 | client_pub_uri = optarg; 125 | break; 126 | 127 | case 'i': 128 | heartbeat_interval = atoi(optarg); 129 | break; 130 | 131 | case 'l': 132 | heartbeat_liveness = atoi(optarg); 133 | break; 134 | 135 | case 'w': 136 | window_len = atoi(optarg); 137 | break; 138 | 139 | case 'm': 140 | strcpy(metric_prefix, optarg); 141 | break; 142 | 143 | case '?': 144 | case 'v': 145 | fprintf(stderr, "bgpview version %d.%d.%d\n", BGPVIEW_MAJOR_VERSION, 146 | BGPSTREAM_MID_VERSION, BGPSTREAM_MINOR_VERSION); 147 | usage(argv[0]); 148 | return 0; 149 | break; 150 | 151 | default: 152 | usage(argv[0]); 153 | return -1; 154 | break; 155 | } 156 | } 157 | 158 | /* NB: once getopt completes, optind points to the first non-option 159 | argument */ 160 | 161 | if ((server = bgpview_io_zmq_server_init()) == NULL) { 162 | fprintf(stderr, "ERROR: could not initialize bgpview server\n"); 163 | goto err; 164 | } 165 | 166 | bgpview_io_zmq_server_set_metric_prefix(server, metric_prefix); 167 | 168 | if (client_uri != NULL) { 169 | bgpview_io_zmq_server_set_client_uri(server, client_uri); 170 | } 171 | 172 | if (client_pub_uri != NULL) { 173 | bgpview_io_zmq_server_set_client_pub_uri(server, client_pub_uri); 174 | } 175 | 176 | bgpview_io_zmq_server_set_heartbeat_interval(server, heartbeat_interval); 177 | 178 | bgpview_io_zmq_server_set_heartbeat_liveness(server, heartbeat_liveness); 179 | 180 | bgpview_io_zmq_server_set_window_len(server, window_len); 181 | 182 | /* do work */ 183 | /* this function will block until the server shuts down */ 184 | bgpview_io_zmq_server_start(server); 185 | 186 | /* cleanup */ 187 | bgpview_io_zmq_server_free(server); 188 | 189 | /* complete successfully */ 190 | return 0; 191 | 192 | err: 193 | if (server != NULL) { 194 | bgpview_io_zmq_server_free(server); 195 | } 196 | return -1; 197 | } 198 | -------------------------------------------------------------------------------- /tools/io/bvcat.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Regents of the University of California. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #include "bgpview.h" 28 | #include "bgpview_io_file.h" 29 | #include "config.h" 30 | #include "utils.h" 31 | #include 32 | #include 33 | 34 | static bgpview_t *view = NULL; 35 | static iow_t *wstdout = NULL; 36 | 37 | static int cat_file(const char *file) 38 | { 39 | io_t *infile = NULL; 40 | int ret; 41 | 42 | if ((infile = wandio_create(file)) == NULL) { 43 | goto err; 44 | } 45 | 46 | while ((ret = bgpview_io_file_read(infile, view, NULL, NULL, NULL)) > 0) { 47 | if (bgpview_io_file_print(wstdout, view) != 0) { 48 | goto err; 49 | } 50 | bgpview_clear(view); 51 | } 52 | 53 | if (ret < 0) { 54 | goto err; 55 | } 56 | 57 | if (infile != NULL) { 58 | wandio_destroy(infile); 59 | } 60 | return 0; 61 | 62 | err: 63 | if (infile != NULL) { 64 | wandio_destroy(infile); 65 | } 66 | return -1; 67 | } 68 | 69 | int main(int argc, char **argv) 70 | { 71 | int i; 72 | 73 | if ((view = bgpview_create(NULL, NULL, NULL, NULL)) == NULL) { 74 | goto err; 75 | } 76 | 77 | if ((wstdout = wandio_wcreate("-", WANDIO_COMPRESS_NONE, 0, 0)) == NULL) { 78 | goto err; 79 | } 80 | 81 | if (argc == 1) { 82 | if (cat_file("-") != 0) { 83 | goto err; 84 | } 85 | } else { 86 | for (i = 1; i < argc; i++) { 87 | if (cat_file(argv[i]) != 0) { 88 | goto err; 89 | } 90 | } 91 | } 92 | 93 | if (stdout != NULL) { 94 | wandio_wdestroy(wstdout); 95 | } 96 | bgpview_destroy(view); 97 | return 0; 98 | 99 | err: 100 | if (wstdout != NULL) { 101 | wandio_wdestroy(wstdout); 102 | } 103 | bgpview_destroy(view); 104 | return -1; 105 | } 106 | --------------------------------------------------------------------------------