def __init__(self): """ Initialization of the Learning Switch. The important piece is the definition of the switch mapping. This is a nested dictionary. """ # Initialize the parent class super(LearningSwitch, self).__init__() # initialize the forwarding table to empty. # This may need to be updated if a different topology is used. self.fwd_table = {} self.fwd_table['1'] = {} self.fwd_table['2'] = {} self.fwd_table['3'] = {} self.fwd_table['4'] = {} self.fwd_table['5'] = {} # only use one flood instance - this is the default policy self.flood = flood() # get the first packet from each new MAC address on a switch new_pkts = packets(1, ['dstmac', 'switch']) new_pkts.register_callback(self.learn_route) self.query = new_pkts # Initialize the policy self.push_rules()
def __init__(self): """ Initialization of the Learning Switch. The important piece is the definition of the switch mapping. This is a nested dictionary. """ # Initialize the parent class super(LearningSwitch, self).__init__() # TODO: Initialize your forwarding tables. Create this however you wish. # Couple of suggestions: Dictionary of dictionaries, Dictionary of # tuples. self.forward_table = {} self.forward_table['1'] = {} self.forward_table['2'] = {} self.forward_table['3'] = {} self.forward_table['4'] = {} self.forward_table['5'] = {} # only use one flood instance - this is the default policy when there # isn't a known path. self.flood = flood() # Get the first packet from each new MAC address on a switch. This # is how we are able to learn new routes. new_pkts = packets(1, ['srcmac', 'switch']) new_pkts.register_callback(self.learn_route) self.query = new_pkts # Initialize the policy self.build_policy()
def __init__(self): """ Initialization of the Learning Switch. The important piece is the definition of the switch mapping. This is a nested dictionary. """ # Initialize the parent class super(LearningSwitch, self).__init__() # TODO: Initialize your forwarding tables. Create this however you wish. # Couple of suggestions: Dictionary of dictionaries, Dictionary of # tuples. self.forwardTable = [] self.forwardTable = [(1, "00:00:00:00:00:01", 3), (1, "00:00:00:00:00:02", 2)] # only use one flood instance - this is the default policy when there # isn't a known path. self.flood = flood() # Get the first packet from each new MAC address on a switch. This # is how we are able to learn new routes. new_pkts = packets(1, ['srcmac', 'switch']) new_pkts.register_callback(self.learn_route) self.query = new_pkts # Initialize the policy self.build_policy()
def __init__(self): """ Initialization of the Learning Switch. The important piece is the definition of the switch mapping. This is a nested dictionary. """ # Initialize the parent class super(LearningSwitch, self).__init__() # TODO: Initialize your forwarding tables. Create this however you wish. # Couple of suggestions: Dictionary of dictionaries, Dictionary of # tuples. # initialize the forwarding table to empty. # base on the learn-swtch-topo, it has s1->s5 self.forward_table = {} # the s1-s5 switch fw table self.forward_table[1] = {} self.forward_table[2] = {} self.forward_table[3] = {} self.forward_table[4] = {} self.forward_table[5] = {} # only use one flood instance - this is the default policy when there # isn't a known path. self.flood = flood() # Get the first packet from each new MAC address on a switch. This # is how we are able to learn new routes. new_pkts = packets(1, ['srcmac', 'switch']) new_pkts.register_callback(self.learn_route) self.query = new_pkts # Initialize the policy self.build_policy()
def __init__(self): """ Initialization of the Learning Switch. The important piece is the definition of the switch mapping. This is a nested dictionary. """ # Initialize the parent class super(LearningSwitch, self).__init__() # initialize the forwarding table to empty. # This may need to be updated if a different topology is used. self.fwd_table = {} self.fwd_table['1'] = {} self.fwd_table['2'] = {} self.fwd_table['3'] = {} self.fwd_table['4'] = {} self.fwd_table['5'] = {} # only use one flood instance - this is the default policy self.flood = flood() # get the first packet from each new MAC address on a switch new_pkts = packets(1, ['srcmac', 'switch']) new_pkts.register_callback(self.learn_route) self.query = new_pkts # Initialize the policy self.push_rules()
def reset(self): # policy = self.cls(self.kwargs) # print type(policy) # print policy # self.policy = policy self.policy = query.packets(limit=1, group_by=['srcmac', 'switch']) # print type(self.policy) # print self.policy self.policy.register_callback(self.callback)
def reset(self): # policy = self.cls(self.kwargs) # print type(policy) # print policy # self.policy = policy self.policy = query.packets(limit=1,group_by=['srcmac','switch']) # print type(self.policy) # print self.policy self.policy.register_callback(self.callback)
def set_policy(self): # This is the default policy for the firwall switch. Non-DNS packets # get forwarded automatically, DNS packets go through the student code. non_dns_traffic = ~match(ethtype=2048, protocol=17, srcport = 53) >> ~match(ethtype=2048, protocol=17, dstport = 53) >> flood() # Getting all DNS traffic. dnspkts = packets(None, ['srcmac']) dnspkts.register_callback(self.dns_callback) dns_inbound = match(ethtype=2048, protocol=17, srcport = 53) >> dnspkts dns_outbound = match(ethtype=2048, protocol=17, dstport = 53) >> dnspkts # Compose the subpolicies for Non-DNS traffic and for capturing the # DNS traffic and forwarding to the appropriate locations # self.policy is a special variable. self.policy = non_dns_traffic + dns_inbound + dns_outbound
def __init__(self): DynamicPolicy.__init__(self) # Initialize the forwarding table self.fwd_table = {} # Use flooding at first self.flood = flood() # Get the first packet from each new MAC address on a switch new_pkts = packets(1, ['srcmac', 'switch']) new_pkts.register_callback(self.learn_route) self.query = new_pkts # Initialize the policy self.push_rules()
def __init__(self): """ Initialization of the Learning Switch. The important piece is the definition of the switch mapping. This is a nested dictionary. """ # Initialize the parent class super(LearningSwitch, self).__init__() # Initialize logfile init_log("learning-switch.log") # Do NOT edit this line # TODO: Initialize your forwarding tables. Create this however you wish. # Couple of suggestions: Dictionary of dictionaries, Dictionary of # tuples. self.forwardingTable = {} # NOTE: (Python tip) if you create a variable like this... # foo = 42 # that will be a local variable, only accessible in this function. # # But if you create a variable like this... # self.foo = 42 # that will be a class member that is accessible from other class # methods (functions), such as build_policy(), but remember to use # "self" *every* time you access it, or you'll access a local variable # instead of the class member! # Only use one flood instance - this is the default policy when there # isn't a known path. self.flood = flood() # Get the first packet from each new MAC address on a switch. This # is how we are able to learn new routes. new_pkts = packets(1, ['srcmac', 'switch']) new_pkts.register_callback(self.learn_route) self.query = new_pkts # Initialize the policy self.build_policy()
def __init__(self): """ Initialization of the Learning Switch. The important piece is the definition of the switch mapping. This is a nested dictionary. """ # Initialize the parent class super(LearningSwitch, self).__init__() # Initialize logfile init_log("learning-switch.log") # Do NOT edit this line # TODO: Initialize your forwarding tables. Create this however you wish. # Couple of suggestions: Dictionary of dictionaries, Dictionary of # tuples. # NOTE: (Python tip) if you create a variable like this... # foo = 42 # that will be a local variable, only accessible in this function. # # But if you create a variable like this... # self.foo = 42 # that will be a class member that is accessible from other class # methods (functions), such as build_policy(), but remember to use # "self" *every* time you access it, or you'll access a local variable # instead of the class member! # Only use one flood instance - this is the default policy when there # isn't a known path. self.flood = flood() # Get the first packet from each new MAC address on a switch. This # is how we are able to learn new routes. new_pkts = packets(1, ['srcmac', 'switch']) new_pkts.register_callback(self.learn_route) self.query = new_pkts # Initialize the policy self.build_policy()