The Assimilation Project  based on Assimilation version 0.5.1435932971
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
pcap+mainloop.c File Reference

vim: smartindent number syntax=c More...

#include <projectcommon.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <framesettypes.h>
#include <frameset.h>
#include <ctype.h>
#include <netgsource.h>
#include <reliableudp.h>
#include <netaddr.h>
#include <authlistener.h>
#include <signframe.h>
#include <cryptframe.h>
#include <compressframe.h>
#include <intframe.h>
#include <addrframe.h>
#include <cstringframe.h>
#include <frametypes.h>
#include <nanoprobe.h>
#include <resourcecmd.h>
#include <cmalib.h>
#include <cryptcurve25519.h>
Include dependency graph for pcap+mainloop.c:

Go to the source code of this file.

Macros

#define TESTPORT   1984
 
#define CRYPTO_KEYID   CMA_KEY_PREFIX "999999b"
 
#define OCFCLASS   "\"" REQCLASSNAMEFIELD "\": \"ocf\""
 
#define HBPROVIDER   "\"" REQPROVIDERNAMEFIELD "\": \"heartbeat\""
 
#define DUMMYTYPE   "\"" CONFIGNAME_TYPE "\": \"Dummy\""
 
#define STARTOP   "\"" REQOPERATIONNAMEFIELD "\": \"start\""
 
#define STOPOP   "\"" REQOPERATIONNAMEFIELD "\": \"stop\""
 
#define UMONITOROP   "\"" REQOPERATIONNAMEFIELD "\": \""MONITOROP"\""
 
#define UMETADATAOP   "\"" REQOPERATIONNAMEFIELD "\": \""METADATAOP"\""
 
#define RESOURCENAME   "\"" CONFIGNAME_INSTANCE "\": \"DummyTestGTest01\""
 
#define NULLPARAMS   "\"" REQENVIRONNAMEFIELD "\": {}"
 
#define C   ","
 
#define REQID(id)   "\"" REQIDENTIFIERNAMEFIELD "\": " #id
 
#define REPEAT(repeat)   "\"" REQREPEATNAMEFIELD "\": " #repeat
 
#define INITDELAY(delay)   "\"" CONFIGNAME_INITDELAY "\": " #delay
 
#define COMMREQUEST   OCFCLASS C HBPROVIDER C DUMMYTYPE C RESOURCENAME C NULLPARAMS
 
#define REQUEST(type, id, repeat, delay)   "{" COMMREQUEST C type C REQID(id) C REPEAT(repeat) C INITDELAY(delay)"}"
 
#define START   REQUEST(STARTOP, 1, 0, 0)
 
#define MONITOR   REQUEST(UMONITOROP, 2, 0, 0)
 
#define STOP   REQUEST(STOPOP, 3, 0, 5)
 
#define ETHNAME   "eth0"
 
#define ETHDEV   "\"" CONFIGNAME_DEVNAME "\": \"" ETHNAME "\""
 
#define SWTYPE   "\"" CONFIGNAME_TYPE "\": \"#SWITCH\""
 
#define SWINST   "\"" CONFIGNAME_INSTANCE "\": \"#_SWITCH_" ETHNAME "\""
 
#define SWINSTNM   "#_SWITCH_" ETHNAME
 
#define SWPROTOS   "\"" CONFIGNAME_SWPROTOS "\": [\"lldp\", \"cdp\"]"
 
#define ARPTYPE   "\"" CONFIGNAME_TYPE "\": \"#ARP\""
 
#define ARPINST   "\"" CONFIGNAME_INSTANCE "\": \"#_ARP_" ETHNAME "\""
 
#define ARPINSTNM   "#_ARP_" ETHNAME
 
#define SWITCHDISCOVER   "{" SWTYPE ", " SWINST ", " ETHDEV ", " SWPROTOS "}"
 
#define ARPDISCOVER   "{" ARPTYPE ", " ARPINST ", " ETHDEV "}"
 

Functions

gboolean gotnetpkt (Listener *l,FrameSet *fs,NetAddr *srcaddr)
 Test routine called when an otherwise-unclaimed NetIO packet is received. More...
 
void got_heartbeat (HbListener *who)
 
void got_heartbeat2 (HbListener *who)
 
void check_JSON (FrameSet *fs)
 
FSTATIC gboolean test_cma_authentication (const FrameSet *fs, NetAddr *fromaddr)
 Routine to (fake) validate that we have proper authentication... More...
 
void fakecma_startup (AuthListener *auth, FrameSet *ifs, NetAddr *nanoaddr)
 Routine to pretend to be the initial CMA. More...
 
gboolean timeout_agent (gpointer ignored)
 Called every second during tests. More...
 
int main (int argc, char **argv)
 Test program looping and reading LLDP/CDP packets and exercising most of the packet send/receive mechanism and a good bit of nanoprobe and CMA basic infrastructure. More...
 

Variables

int errcount
 error count More...
 
NanoHbStats nano_hbstats
 
GMainLoop * mainloop
 gtest01.c - miscellaneous glib mainloop-based tests. More...
 
int expected_dead_count = 1
 
gint64 maxpkts = G_MAXINT64
 
gint64 pktcount = 0
 
NetIOnettransport
 
NetGSourcenetpkt
 
NetAddrdestaddr
 
NetAddrotheraddr
 
NetAddrotheraddr2
 
NetAddranyaddr
 
int wirepktcount = 0
 
ObeyFrameSetTypeMap cmalist []
 
ConfigContextnanoconfig
 

Detailed Description

vim: smartindent number syntax=c

Simple pcap testing code using 'mainloop'. Listens for CDP or LLDP packets on the network - all using the mainloop dispatch code. Probably a short-lived piece of test code. Well... Maybe not so short-lived, but definitely basic testing.

Here's what it does at the moment:

  • listen for LLDP or CDP packets and: demarshall them and remarshall them to see if they're the same
  • listen for heartbeats - and there won't be any at first When we have declared ourself dead, we begin to send ourselves heartbeats. The first one will be declared late, but the remaining ones should be on time. The software is built to expect this behavior from itself and print info messages when things go as they should, and warning messages when things deviate from expectations.

This file is part of the Assimilation Project.

Author
Copyright © 2011, 2012 - Alan Robertson alanr.nosp@m.@uni.nosp@m.x.sh
The Assimilation software is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

The Assimilation software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with the Assimilation Project software. If not, see http://www.gnu.org/licenses/

Definition in file pcap+mainloop.c.

Macro Definition Documentation

#define ARPDISCOVER   "{" ARPTYPE ", " ARPINST ", " ETHDEV "}"

Definition at line 232 of file pcap+mainloop.c.

Referenced by fakecma_startup().

#define ARPINST   "\"" CONFIGNAME_INSTANCE "\": \"#_ARP_" ETHNAME "\""

Definition at line 229 of file pcap+mainloop.c.

#define ARPINSTNM   "#_ARP_" ETHNAME

Definition at line 230 of file pcap+mainloop.c.

Referenced by fakecma_startup().

#define ARPTYPE   "\"" CONFIGNAME_TYPE "\": \"#ARP\""

Definition at line 228 of file pcap+mainloop.c.

#define C   ","

Definition at line 211 of file pcap+mainloop.c.

Definition at line 215 of file pcap+mainloop.c.

#define CRYPTO_KEYID   CMA_KEY_PREFIX "999999b"

Definition at line 65 of file pcap+mainloop.c.

#define DUMMYTYPE   "\"" CONFIGNAME_TYPE "\": \"Dummy\""

Definition at line 204 of file pcap+mainloop.c.

#define ETHDEV   "\"" CONFIGNAME_DEVNAME "\": \"" ETHNAME "\""

Definition at line 223 of file pcap+mainloop.c.

#define ETHNAME   "eth0"

Definition at line 222 of file pcap+mainloop.c.

#define HBPROVIDER   "\"" REQPROVIDERNAMEFIELD "\": \"heartbeat\""

Definition at line 203 of file pcap+mainloop.c.

#define INITDELAY (   delay)    "\"" CONFIGNAME_INITDELAY "\": " #delay

Definition at line 214 of file pcap+mainloop.c.

#define MONITOR   REQUEST(UMONITOROP, 2, 0, 0)

Definition at line 219 of file pcap+mainloop.c.

Referenced by fakecma_startup().

#define NULLPARAMS   "\"" REQENVIRONNAMEFIELD "\": {}"

Definition at line 210 of file pcap+mainloop.c.

#define OCFCLASS   "\"" REQCLASSNAMEFIELD "\": \"ocf\""

Definition at line 202 of file pcap+mainloop.c.

#define REPEAT (   repeat)    "\"" REQREPEATNAMEFIELD "\": " #repeat

Definition at line 213 of file pcap+mainloop.c.

#define REQID (   id)    "\"" REQIDENTIFIERNAMEFIELD "\": " #id

Definition at line 212 of file pcap+mainloop.c.

#define REQUEST (   type,
  id,
  repeat,
  delay 
)    "{" COMMREQUEST C type C REQID(id) C REPEAT(repeat) C INITDELAY(delay)"}"

Definition at line 216 of file pcap+mainloop.c.

#define RESOURCENAME   "\"" CONFIGNAME_INSTANCE "\": \"DummyTestGTest01\""

Definition at line 209 of file pcap+mainloop.c.

#define START   REQUEST(STARTOP, 1, 0, 0)

Definition at line 218 of file pcap+mainloop.c.

Referenced by fakecma_startup().

#define STARTOP   "\"" REQOPERATIONNAMEFIELD "\": \"start\""

Definition at line 205 of file pcap+mainloop.c.

#define STOP   REQUEST(STOPOP, 3, 0, 5)

Definition at line 220 of file pcap+mainloop.c.

Referenced by fakecma_startup().

#define STOPOP   "\"" REQOPERATIONNAMEFIELD "\": \"stop\""

Definition at line 206 of file pcap+mainloop.c.

#define SWINST   "\"" CONFIGNAME_INSTANCE "\": \"#_SWITCH_" ETHNAME "\""

Definition at line 225 of file pcap+mainloop.c.

#define SWINSTNM   "#_SWITCH_" ETHNAME

Definition at line 226 of file pcap+mainloop.c.

Referenced by fakecma_startup().

#define SWITCHDISCOVER   "{" SWTYPE ", " SWINST ", " ETHDEV ", " SWPROTOS "}"

Definition at line 231 of file pcap+mainloop.c.

Referenced by fakecma_startup().

#define SWPROTOS   "\"" CONFIGNAME_SWPROTOS "\": [\"lldp\", \"cdp\"]"

Definition at line 227 of file pcap+mainloop.c.

#define SWTYPE   "\"" CONFIGNAME_TYPE "\": \"#SWITCH\""

Definition at line 224 of file pcap+mainloop.c.

#define TESTPORT   1984

Definition at line 64 of file pcap+mainloop.c.

Referenced by main().

#define UMETADATAOP   "\"" REQOPERATIONNAMEFIELD "\": \""METADATAOP"\""

Definition at line 208 of file pcap+mainloop.c.

#define UMONITOROP   "\"" REQOPERATIONNAMEFIELD "\": \""MONITOROP"\""

Definition at line 207 of file pcap+mainloop.c.

Function Documentation

void check_JSON ( FrameSet fs)

Definition at line 107 of file pcap+mainloop.c.

References _CstringFrame::baseclass, _ConfigContext::baseclass, CASTTOCLASS, obsolete_cma::config, configcontext_new_JSON_string(), errcount, _FrameSet::framelist, FRAMETYPE_JSDISCOVER, _AssimObj::toString, _Frame::type, UNREF, and _Frame::value.

Referenced by fakecma_startup(), and gotnetpkt().

Here is the call graph for this function:

Here is the caller graph for this function:

void got_heartbeat ( HbListener who)
void got_heartbeat2 ( HbListener who)
gboolean gotnetpkt ( Listener l,
FrameSet fs,
NetAddr srcaddr 
)

Test routine called when an otherwise-unclaimed NetIO packet is received.

Parameters
[in,out]lInput GSource
[in,out]fsFrameSets received
[in]srcaddrSource address of this packet

Definition at line 142 of file pcap+mainloop.c.

References _NetGSource::_netio, _NetIO::ackmessage(), _FrameSet::baseclass, check_JSON(), FRAMESETTYPE_HBDEAD, FRAMESETTYPE_JSDISCOVERY, FRAMESETTYPE_RSCOPREPLY, FRAMESETTYPE_SWDISCOVER, FREE, _FrameSet::fstype, maxpkts, nano_initiate_shutdown(), _AssimObj::toString, _Listener::transport, UNREF, and wirepktcount.

Referenced by main().

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Test program looping and reading LLDP/CDP packets and exercising most of the packet send/receive mechanism and a good bit of nanoprobe and CMA basic infrastructure.

It plays both sides of the game - the CMA and the nanoprobe.

It leaves most of the work of starting up the nanoprobe code to nano_start_full()

Definition at line 349 of file pcap+mainloop.c.

References _ReliableUDP::_protocol, _NetGSource::addListener, _Listener::associate, authlistener_new(), _NetIOudp::baseclass, _AuthListener::baseclass, _ReliableUDP::baseclass, _NetGSource::baseclass, _SignFrame::baseclass, _NetIO::bindaddr(), obsolete_cma::config, configcontext_new(), CONFIGNAME_CMAADDR, CONFIGNAME_CMADISCOVER, CONFIGNAME_CMAFAIL, CONFIGNAME_CMAINIT, CONFIGNAME_CMAPORT, CONFIGNAME_INTERVAL, CONFIGNAME_OUTSIG, CONFIGNAME_TIMEOUT, CONST_IPV6_LOOPBACK, _Listener::dissociate, errcount, FMT_64BIT, _Listener::got_frameset, gotnetpkt(), listener_new(), mainloop, maxpkts, _NetIO::mcastjoin(), nano_packet_decoder(), nano_shutdown(), nano_start_full(), netaddr_ipv4_new(), netaddr_ipv6_new(), netgsource_new(), netio_is_dual_ipv4v6_stack(), proj_class_dump_live_objects(), proj_class_finalize_sys(), proj_class_incr_debug(), proj_class_live_object_count(), reliableudp_new(), _ConfigContext::setaddr, _ConfigContext::setframe, _ConfigContext::setint, signframe_glib_new(), test_cma_authentication(), TESTPORT, timeout_agent(), UNREF, UNREF2, _FsProtocol::window_size, and wirepktcount.

Here is the call graph for this function:

FSTATIC gboolean test_cma_authentication ( const FrameSet fs,
NetAddr fromaddr 
)

Routine to (fake) validate that we have proper authentication...

For our purposes, we don't much care how it's encrypted...

Definition at line 325 of file pcap+mainloop.c.

References _FrameSet::baseclass, CASTTOCLASS, DUMP, _FrameSet::framelist, FRAMETYPE_CRYPTCURVE25519, and _Frame::type.

Referenced by main().

Here is the caller graph for this function:

gboolean timeout_agent ( gpointer  ignored)

Called every second during tests.

Definition at line 188 of file pcap+mainloop.c.

References _ReliableUDP::_protocol, CASTTOCLASS, _FsProtocol::closeall, _NanoHbStats::heartbeat_count, maxpkts, and nano_initiate_shutdown().

Referenced by main().

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

NetAddr* anyaddr

Definition at line 86 of file pcap+mainloop.c.

Referenced by _netaddr_isanyaddr(), and main().

Initial value:
= {
{0, NULL},
}
#define FRAMESETTYPE_STARTUP
Nanoprobe originating packet is starting up.
Definition: framesettypes.h:35
void fakecma_startup(AuthListener *, FrameSet *fs, NetAddr *)
Routine to pretend to be the initial CMA.

Definition at line 98 of file pcap+mainloop.c.

NetAddr* destaddr

Definition at line 83 of file pcap+mainloop.c.

int expected_dead_count = 1

Definition at line 77 of file pcap+mainloop.c.

gint64 maxpkts = G_MAXINT64

Definition at line 78 of file pcap+mainloop.c.

Referenced by gotnetpkt(), main(), and timeout_agent().

ConfigContext* nanoconfig

Definition at line 104 of file pcap+mainloop.c.

NetGSource* netpkt

Definition at line 82 of file pcap+mainloop.c.

NetIO* nettransport

Definition at line 81 of file pcap+mainloop.c.

NetAddr* otheraddr

Definition at line 84 of file pcap+mainloop.c.

NetAddr* otheraddr2

Definition at line 85 of file pcap+mainloop.c.

gint64 pktcount = 0

Definition at line 79 of file pcap+mainloop.c.

int wirepktcount = 0

Definition at line 87 of file pcap+mainloop.c.

Referenced by gotnetpkt(), and main().