The Assimilation Project
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pcap+mainloop.c File Reference

Simple pcap testing code using 'mainloop'. 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 dependency graph for pcap+mainloop.c:

Go to the source code of this file.

Macros

#define TESTPORT   1984
 
#define OCFCLASS   "\"" REQCLASSNAMEFIELD "\": \"ocf\""
 
#define HBPROVIDER   "\"" REQPROVIDERNAMEFIELD "\": \"heartbeat\""
 
#define DUMMYTYPE   "\"" REQTYPENAMEFIELD "\": \"Dummy\""
 
#define STARTOP   "\"" REQOPERATIONNAMEFIELD "\": \"start\""
 
#define STOPOP   "\"" REQOPERATIONNAMEFIELD "\": \"stop\""
 
#define MONITOROP   "\"" REQOPERATIONNAMEFIELD "\": \"monitor\""
 
#define METADATAOP   "\"" REQOPERATIONNAMEFIELD "\": \"meta-data\""
 
#define RESOURCENAME   "\"" REQRSCNAMEFIELD "\": \"DummyTestGTest01\""
 
#define NULLPARAMS   "\"" REQENVIRONNAMEFIELD "\": {}"
 
#define C   ","
 
#define REQID(id)   "\"" REQIDENTIFIERNAMEFIELD "\": " #id
 
#define REPEAT(repeat)   "\"" REQREPEATNAMEFIELD "\": " #repeat
 
#define INITDELAY(delay)   "\"" REQINITDELAYNAMEFIELD "\": " #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(MONITOROP, 2, 0, 0)
 
#define STOP   REQUEST(STOPOP, 3, 0, 5)
 

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)
 
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

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 C   ","

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

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

#define DUMMYTYPE   "\"" REQTYPENAMEFIELD "\": \"Dummy\""

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

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

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

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

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

#define METADATAOP   "\"" REQOPERATIONNAMEFIELD "\": \"meta-data\""

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

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

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

Referenced by fakecma_startup().

#define MONITOROP   "\"" REQOPERATIONNAMEFIELD "\": \"monitor\""

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

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

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

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

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

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

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

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

Definition at line 204 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 208 of file pcap+mainloop.c.

#define RESOURCENAME   "\"" REQRSCNAMEFIELD "\": \"DummyTestGTest01\""

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

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

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

Referenced by fakecma_startup().

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

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

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

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

Referenced by fakecma_startup().

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

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

#define TESTPORT   1984

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

Referenced by main().

Function Documentation

void check_JSON ( FrameSet fs)

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

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

Referenced by fakecma_startup().

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
int main ( int  argc,
char **  argv 
)
gboolean timeout_agent ( gpointer  ignored)

Called every second during tests.

Definition at line 180 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 84 of file pcap+mainloop.c.

Referenced by _netaddr_isanyaddr(), and main().

Initial value:

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

NetAddr* destaddr

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

int expected_dead_count = 1

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

gint64 maxpkts = G_MAXINT64

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

Referenced by main(), and timeout_agent().

ConfigContext* nanoconfig

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

NetGSource* netpkt

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

NetIO* nettransport

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

NetAddr* otheraddr

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

NetAddr* otheraddr2

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

gint64 pktcount = 0

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

int wirepktcount = 0

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