/TopologyManager/main.py

https://github.com/tsilochr/blackadder
Python | 63 lines | 39 code | 12 blank | 12 comment | 2 complexity | d878619cbebbbc63cd231785cf5e1d7a MD5 | raw file
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. # main.py TmEngine entry point.
  4. # Author: Dimitris Syrivelis
  5. # ITI CERTH for Pursuit project. This source is under BlackAdder license
  6. import select
  7. import socket
  8. import time
  9. import signal
  10. import struct
  11. import TMIgraph
  12. import BlackAdderTMCore
  13. import TMPacket
  14. import BlackAdderConnection
  15. from array import *
  16. import sys
  17. import os
  18. import math
  19. import string
  20. import traceback
  21. import getopt
  22. import BitVector
  23. from config import Config
  24. from impacket import ImpactPacket
  25. global tigraph
  26. def signal_handler(signal, frame):
  27. '''This is the signal handler for Ctrl-C, it does not work as expected...'''
  28. print 'Graceful Exit due to Ctrl-C!'
  29. bcon.disconnect()
  30. tigraph.kill()
  31. sys.exit(0)
  32. #Welcome Message
  33. print "====BlackAdder Topology Manager Version 0.1===="
  34. #Execution begins here. Firstly register a handler for Ctrl-C
  35. signal.signal(signal.SIGINT, signal_handler)
  36. #TmIgraph module gets configuration maps, uses igraph library to handle packet requests and produces response packets to the outgoing Queue
  37. tigraph = TMIgraph.TMIgraphModule(sys.argv[1])
  38. # Open the connection to BlackAdder
  39. bcon = BlackAdderConnection.Connection(tigraph.mode)
  40. tigraph.setCon(bcon)
  41. #Subscribe to the hardcoded TM scope
  42. tmscopeid = array('B',[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe])
  43. tmprefixid = array('B', [])
  44. bcon.publishAction(bcon.SUBSCRIBE_SCOPE, tmscopeid.tostring(), tmprefixid.tostring(), bcon.SUBSCRIBE_LOCALLY)
  45. tigraph.start()
  46. #ingress main loop. receives packets from BlackAdder Netlink interface and adds them to a processor queue. Currently only TMigraph is available
  47. while 1:
  48. pckt=bcon.recv()
  49. if(pckt[0] == bcon.PUBLISHED_DATA):
  50. data = pckt[3]
  51. tigraph.IngressPut(data)