Skip to content

Commit

Permalink
Merge branch 'debugging-rule-installs'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Donovan committed Dec 3, 2019
2 parents ba1685f + 26ebe3c commit e123559
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 18 deletions.
4 changes: 2 additions & 2 deletions configuration/awave-deployment/awave.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"localcontrollers": {
"gt-ctlr-149-223": {
"shortname":"SoXctlr",
"shortname":"gt-ctlr-149-223",
"credentials":"pwd",
"location":"0,0",
"lcip":"127.0.0.1",
Expand Down Expand Up @@ -62,7 +62,7 @@
}
},
"mia-ctlr-186-106": {
"shortname":"miactlr",
"shortname":"mia-ctlr-186-106",
"credentials":"pwd",
"location":"0,0",
"lcip":"127.0.0.1",
Expand Down
2 changes: 2 additions & 0 deletions docker/pseudo_dtn/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def run_transfer_thread(remote, filename):
class Dir(Resource):
def get(self, remote):
# Get connection with FTP
print("Dir GET: %s" % remote)
ftp = FTP(remote)
ftp.login(user='anonymous', passwd='')

Expand All @@ -163,6 +164,7 @@ class Status(Resource):
def get(self):
global in_progress
global total_time
print("Status GET")
retval = ("%s-%s" % (in_progress, total_time))
print("GET status: %s" % retval)
return retval
Expand Down
12 changes: 7 additions & 5 deletions docker/sci_gw_demo/science_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,16 @@ def create_tunnel(srcswitch, dstswitch, srcport, dstport,
login_to_sdx_controller()

# Calculate start and end times
#starttime = datetime.now() - time

#starttime = datetime.now()
#endtime = starttime + time
# Hardwiring these, so that this will always be installable
starttime = datetime(1999, 01, 01)
endtime = datetime(2030, 01, 01)
starttime = datetime.datetime(1999, 01, 01)
endtime = datetime.datetime(2030, 01, 01)

# Issue POST command
endpoint = "http://%s:%s/api/v1/policies/type/l2tunnel" % (sdx_ip, sdx_port)

# Issue POST command
endpoint = "http://%s:%s/api/v1/policies/type/L2Tunnel" % (sdx_ip, sdx_port)
l2tunnel = '{"L2Tunnel":{"starttime":"%s","endtime":"%s","srcswitch":"%s","dstswitch":"%s","srcport":%s,"dstport":%s,"srcvlan":%s,"dstvlan":%s,"bandwidth":10000000}}' % (
starttime.strftime(rfc3339format), endtime.strftime(rfc3339format),
srcswitch, dstswitch, srcport, dstport, srcvlan, dstvlan)
Expand Down
13 changes: 11 additions & 2 deletions lib/AtlanticWaveConnectionManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class AtlanticWaveConnectionManager(AtlanticWaveModule):
on. One per incoming connection. One for outbound connections. Needs to
be subclassed, even though much will be in common. Singleton. '''

def __init__(self, loggerid, connection_cls=Connection):
def __init__(self, loggerid, connection_cls=Connection, loggerid_for_connections=None):

super(AtlanticWaveConnectionManager, self).__init__(loggerid)

Expand All @@ -36,6 +36,7 @@ def __init__(self, loggerid, connection_cls=Connection):
raise TypeError("%s is not a Connection type." %
str(connection_cls))
self.connection_cls = connection_cls
self.loggerid_for_cxns = loggerid_for_connections
self.listening_callback = None

def __repr__(self):
Expand Down Expand Up @@ -114,7 +115,12 @@ def _internal_new_connection(self, sock, address):
passes this to the saved new connection handling function.
Private. '''
client_ip, client_port = address
client_connection = self.connection_cls(client_ip, client_port, sock)
client_connection = None
if(self.loggerid_for_cxns != None):
client_connection = self.connection_cls(client_ip, client_port, sock,
self.loggerid_for_cxn)
else:
client_connection = self.connection_cls(client_ip, client_port, sock)
self.clients.append(client_connection)
self.listening_callback(client_connection)

Expand All @@ -140,5 +146,8 @@ def open_outbound_connection(self, host, port):
continue

print "Connection established! %s:%s %s" % (ip, port, sock)
if self.loggerid_for_cxns != None:
return self.connection_cls(ip, port, sock, self.loggerid_for_cxns)
#else
return self.connection_cls(ip, port, sock)

36 changes: 35 additions & 1 deletion lib/Connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ class Connection(object):
it'll be a socket, but in the future, this can be changed to be a TLS
socket, for instance. '''

def __init__(self, address, port, sock):
def __init__(self, address, port, sock, loggerid=None):
# Setup logging
self.loggerid = None
if loggerid != None:
self.loggerid = loggerid + str(self.__class__.__name__)
self._setup_loggers(self.loggerid)

# Validate incoming variables
# Skipping address and port for now.
Expand Down Expand Up @@ -63,6 +67,36 @@ def __str__(self):
retval += " sock: %s\n" % self.sock
return retval

def _setup_loggers(self, loggerid, logfilename=None, debuglogfilename=None):
''' Internal function for setting up the logger formats. '''
# reused from https://github.com/sdonovan1985/netassay-ryu/blob/master/base/mcm.py
# Modified based on https://stackoverflow.com/questions/7173033/
self.logger = logging.getLogger(loggerid)
self.dlogger = logging.getLogger("debug." + loggerid)
if logfilename != None:
formatter = logging.Formatter('%(asctime)s %(name)-12s: %(thread)s %(levelname)-8s %(message)s')
console = logging.StreamHandler()
console.setLevel(logging.DEBUG)
console.setFormatter(formatter)
logfile = logging.FileHandler(logfilename)
logfile.setLevel(logging.DEBUG)
logfile.setFormatter(formatter)
self.logger.setLevel(logging.DEBUG)
self.logger.addHandler(console)
self.logger.addHandler(logfile)

if debuglogfilename != None:
formatter = logging.Formatter('%(asctime)s %(name)-12s: %(thread)s %(levelname)-8s %(message)s')
console = logging.StreamHandler()
console.setLevel(logging.DEBUG)
console.setFormatter(formatter)
logfile = logging.FileHandler(debuglogfilename)
logfile.setLevel(logging.DEBUG)
logfile.setFormatter(formatter)
self.dlogger.setLevel(logging.DEBUG)
self.dlogger.addHandler(console)
self.dlogger.addHandler(logfile)

def get_address(self):
return self.address
def get_port(self):
Expand Down
15 changes: 12 additions & 3 deletions sdxctlr/RuleManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ def get_breakdown_rules_by_LC(self, lc):
startup by the SDXController.
Returns a list of broken down rules.
'''
self.logger.info("get_breakdown_rules_by_LC(%s)" % lc)
bd_list = []
# Get all rules
all_rules = self.rule_table.find()
Expand All @@ -288,8 +289,12 @@ def get_breakdown_rules_by_LC(self, lc):
for bd in rule.get_breakdown():
# If Breakdown is for this LC, add to bd_list
rule_lc = bd.get_lc()
self.logger.debug(" Rule with LC %s" % rule_lc)
if rule_lc == lc:
self.logger.info(" Adding %s" % bd)
bd_list += bd.get_list_of_rules()
self.logger.info("get_breakdown_rules_by_LC(%s) - Returning %d rules" %
(lc, len(bd_list)))
return bd_list

def get_rule_details(self, rule_hash):
Expand Down Expand Up @@ -471,6 +476,8 @@ def _add_rule_to_db(self, rule):
state = ACTIVE_RULE
self.dlogger.info(" ACTIVE_RULE")
self._install_rule(rule)
else:
self.dlogger.info(" FUTURE RULE, still INACTIVE")

# Push into DB.
# If there are any changes here, update self._valid_table_columns.
Expand Down Expand Up @@ -550,7 +557,7 @@ def _unreserve_resources(self, resource_list):
def _install_breakdown(self, breakdown):
try:
for bd in breakdown:
self.logger.debug("Sending breakdown: %s" % bd)
self.logger.debug("Sending install breakdown: %s" % bd)
for rule in bd.get_list_of_rules():
self.logger.debug(" %s" % str(rule))
self.send_user_add_rule(bd)
Expand All @@ -562,9 +569,11 @@ def _remove_rule(self, rule):
table_entry = self.rule_table.find_one(hash=rule.get_rule_hash())
extendedbd = pickle.loads(str(table_entry['extendedbd']))
for bd in rule.get_breakdown():
self.logger.debug("Sending remove breakdown: %s" % bd)
self.send_user_rm_rule(bd)
if extendedbd != None:
for bd in extendedbd:
self.logger.debug("Sending remove extended breakdown: %s" % bd)
self.send_user_rm_rule(bd)
self._unreserve_resources(rule.get_resources())
except Exception as e: raise
Expand Down Expand Up @@ -704,7 +713,7 @@ def change_callback_dispatch(self, cookie, data):
'''
table_entry = self.rule_table.find_one(hash=cookie)
if table_entry == None:
raise RuleManagerError("rule_hash doesn't exist: %s" % rule_hash)
raise RuleManagerError("rule_hash doesn't exist: %s" % cookie)

policy = pickle.loads(str(table_entry['rule']))

Expand All @@ -714,7 +723,7 @@ def change_callback_dispatch(self, cookie, data):
if breakdown == None:
return

self.logger.debug("_change_callback_dispath")
self.logger.debug("_change_callback_dispatch %s"% cookie)
self._install_breakdown(breakdown)

extendedbd = pickle.loads(str(table_entry['extendedbd']))
Expand Down
10 changes: 8 additions & 2 deletions shared/SDXControllerConnectionManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class SDXControllerConnectionManager(AtlanticWaveConnectionManager):
def __init__(self, loggeridprefix):
loggerid = loggeridprefix + '.sdxctlrcxnmgr'
super(SDXControllerConnectionManager, self).__init__(
loggerid, SDXControllerConnection)
loggerid, SDXControllerConnection, loggerid)
# associations are for easy lookup of connections based on the name of
# the Local Controller.

Expand Down Expand Up @@ -155,7 +155,13 @@ def _internal_new_connection(self, sock, address):
that adds some callbacks to SDXControllerConnectionManagerConnection
to kick things to the connection queue. '''
client_ip, client_port = address
client_connection = self.connection_cls(client_ip, client_port, sock)
client_connection = None
if (self.loggerid_for_cxns != None):
client_connection = self.connection_cls(
client_ip, client_port, sock, self.loggerid_for_cxns)
else:
client_connection = self.connection_cls(
client_ip, client_port, sock)
client_connection.set_delete_callback(self.add_del_cxn_to_queue)
client_connection.set_new_callback(self.add_new_cxn_to_queue)
self.listening_callback(client_connection)
Expand Down
Loading

0 comments on commit e123559

Please sign in to comment.