def send_msg(self, dp, dir, processing_set): # for filename in processing_set: # full_filename = dir +"/"+filename print "------------------------------------------------------------" print "processing file: %s" % full_filename print "------------------------------------------------------------" # config = ConfigParser.get_config(full_filename) # for type in ConfigParser.get_config_type(config): # if (type == "flow_mod"): mod_config = ConfigParser.get_flow_mod(config) mod = Mods.create_flow_mod(dp, mod_config) # elif (type == "group_mod"): # mod_config = ConfigParser.get_group_mod(config) mod = Mods.create_group_mod(dp, mod_config) # else: print "no such type %s" % type return; print "mod len: %i" % sys.getsizeof(mod) dp.send_msg(mod)
def build_packets(self, dp, dpid): config_dir, _ = ConfigParser.get_working_set(self.CONFIG_FILE) # network config n_prack = self.conf_dict['eps']['phy'][ 'num'] # number of [physical ToRs] n_lrack = self.conf_dict['eps']['log'][ 'num_per_phy'] # number of [logical ToRs] on each [physical ToR] n_server = self.conf_dict['node'][ 'num_per_phy'] / n_lrack # number of [servers] on each [logical ToR] over_subscription = self.conf_dict['eps']['oversubscription'] n_ocs = self.conf_dict['eps']['duplex_10G'][ 'num_per_log'] # number of [ocs links] on each [logical ToR] assert (n_server % over_subscription) == 0 # connectivity port = self.conf_dict['node'][ 'starting'] # starting port number on [each physical rack] port_ocs = self.conf_dict['eps']['duplex_10G'][ 'starting'] # starting port (connecting to ocs) number on [each physical rack] lr_ = self.conf_dict['eps']['log'][ 'vlanid_starting'] # starting logical rack number in the [entire network] ip = self.conf_dict['node'][ 'starting_ip'] # staring ip address of [all servers] ip_10 = "[RESEARCH_NETWORK_PREFIX].111" port_core = 1 # starting port number on [core] # constants core_vlan = self.conf_dict['core']['vlanid'] # vlan number of the core arp_flood_id = self.conf_dict[ 'apr_flood_groupid'] # group_id for the arp flood entry default_queue = self.conf_dict['queue_priority'][ 'default'] # default queue # high_queue = 4 # high priority queue gateway_port_ip = [(self.conf_dict['gateway'][idx]['port'], self.conf_dict['gateway'][idx]['ip'], self.conf_dict['gateway'][idx]['ip_10']) for idx in range(len(self.conf_dict['gateway']))] ip_long = struct.unpack("!L", socket.inet_aton(ip))[0] ip_10_long = struct.unpack("!L", socket.inet_aton(ip_10))[0] template_group_l2_interface_filename = "%s/%s.json" % ( config_dir, "template_group_l2_interface") config = ConfigParser.get_config(template_group_l2_interface_filename) template_vlan_tagged_filename = "%s/%s.json" % (config_dir, "template_vlan_tagged") config_vlan_tagged = ConfigParser.get_config( template_vlan_tagged_filename) template_vlan_untagged_filename = "%s/%s.json" % ( config_dir, "template_vlan_untagged") config_vlan_untagged = ConfigParser.get_config( template_vlan_untagged_filename) template_acl_unicast_filename = "%s/%s.json" % (config_dir, "template_acl_unicast") config_acl_unicast = ConfigParser.get_config( template_acl_unicast_filename) template_acl_unicast_low_filename = "%s/%s.json" % ( config_dir, "template_acl_unicast_low") config_acl_unicast_low = ConfigParser.get_config( template_acl_unicast_low_filename) template_acl_unicast_low_wildcard_filename = "%s/%s.json" % ( config_dir, "template_acl_unicast_low_wildcard") config_acl_unicast_low_wildcard = ConfigParser.get_config( template_acl_unicast_low_wildcard_filename) template_acl_unicast_low_port_filename = "%s/%s.json" % ( config_dir, "template_acl_unicast_low_port") config_acl_unicast_low_port = ConfigParser.get_config( template_acl_unicast_low_port_filename) template_acl_arp_filename = "%s/%s.json" % (config_dir, "template_acl_arp") config_acl_arp = ConfigParser.get_config(template_acl_arp_filename) template_group_l2_multicast_arp_filename = "%s/%s.json" % ( config_dir, "template_group_l2_multicast") config_group_l2_multicast_arp = ConfigParser.get_config( template_group_l2_multicast_arp_filename) template_group_l2_multicast_bucket_arp_filename = "%s/%s.json" % ( config_dir, "template_group_l2_multicast_bucket") config_group_l2_multicast_arp_bucket = ConfigParser.get_config( template_group_l2_multicast_bucket_arp_filename) template_acl_arp_multicast_filename = "%s/%s.json" % ( config_dir, "template_acl_arp_multicast") config_acl_arp_multicast = ConfigParser.get_config( template_acl_arp_multicast_filename) # GROUP & VLAN ENTRIES for all rules @ TORs if 0 < dpid <= 5: lr_offset_ = (dpid - 1) * n_lrack port_offset_ = 0 ip_offset_ = (dpid - 1) * n_lrack * n_server LOG.info("TOR installation setup: " + "logical rack no (" + str(lr_offset_) + "), " + "core port no(" + str(port_offset_) + ")") for lr in range(0, n_lrack): # lr'th logical ToR in physical ToR # rack info vlan_id = lr_ + lr_offset_ # core port RULES (vlan, group) for cc in range(0, n_server / over_subscription): core_port_id = cc + port_core + lr * n_server + n_lrack * n_server # port # connecting to the core # going to core self.create_group_l2_interface(dp, config, vlan_id, core_port_id) # vlan from core self.create_vlan(dp, config_vlan_tagged, config_vlan_untagged, vlan_id, core_port_id) print "core port |", "\tvlan #: ", vlan_id, "\tcore port #: ", core_port_id # server port RULES flood_server_port = [] for ss in range(0, n_server): # ss'th server in lr'th ToR # server info server_port_id = port + port_offset_ server_ip_addr = socket.inet_ntoa( struct.pack('!L', ip_long + ip_offset_)) server_ip_10_addr = socket.inet_ntoa( struct.pack('!L', ip_10_long + ip_offset_)) flood_server_port.append(server_port_id) # core info core_port_id = server_port_id + n_lrack * n_server - ( (server_port_id + n_lrack * n_server - port) % over_subscription) print "server port | ", "\tvlan #: ", vlan_id, "\t", server_ip_addr, "\tserver port #: ", server_port_id, "\tcore port #: ", core_port_id print "server port | ", "\tvlan #: ", vlan_id, "\t", server_ip_10_addr, "\tserver port #: ", server_port_id, "\tcore port #: ", core_port_id # going to server self.create_group_l2_interface(dp, config, vlan_id, server_port_id) # vlan from server self.create_vlan(dp, config_vlan_tagged, config_vlan_untagged, vlan_id, server_port_id) # acl going to server self.create_acl_unicast(dp, config_acl_unicast, vlan_id, server_ip_addr, server_port_id, default_queue) self.create_acl_unicast(dp, config_acl_unicast, vlan_id, server_ip_10_addr, server_port_id, default_queue) # acl going to core @ ToR self.create_acl_unicast_low(dp, config_acl_unicast_low, server_port_id, vlan_id, server_ip_addr, core_port_id, default_queue) self.create_acl_unicast_low(dp, config_acl_unicast_low, server_port_id, vlan_id, server_ip_10_addr, core_port_id, default_queue) # arp going to core self.create_acl_arp(dp, config_acl_arp, server_port_id, vlan_id, core_port_id, default_queue) # arp going to servers if over_subscription == 1: self.create_acl_arp(dp, config_acl_arp, core_port_id, vlan_id, server_port_id, default_queue) ip_offset_ += 1 port_offset_ += 1 if over_subscription > 1: print "arp | ", "\tvlan id: ", vlan_id, "\tports: ", flood_server_port, "\tgroup rule id: ", arp_flood_id + vlan_id self.create_group_l2_flood( dp, config_group_l2_multicast_arp, config_group_l2_multicast_arp_bucket, vlan_id, flood_server_port, arp_flood_id + vlan_id) self.create_acl_arp_flood(dp, config_acl_arp_multicast, vlan_id, default_queue, arp_flood_id + vlan_id) # ocs port rules (vlan, group) for ocs_ in range(0, n_ocs): ocs_port_id = port_ocs + lr * n_ocs + ocs_ print "ocs | ", "\tswitch ocs port: ", ocs_port_id # going to ocs from logical rack self.create_group_l2_interface(dp, config, vlan_id, ocs_port_id) # vlan from ocs self.create_vlan(dp, config_vlan_tagged, config_vlan_untagged, vlan_id, ocs_port_id) # group for multicasting to OCS and ToR @ ToR self.create_group_l2_multicast( dp, config_group_l2_multicast_arp, config_group_l2_multicast_arp_bucket, vlan_id, lr, n_server, ocs_port_id) lr_offset_ += 1 # GROUP & VLAN ENTRIES for all rules @ Core elif dpid == 0: ip_offset_ = 0 # core port RULES (vlan, group) for cc in range(0, n_prack * n_lrack * n_server / over_subscription): core_port_id = over_subscription * cc + 1 # going to core self.create_group_l2_interface(dp, config, core_vlan, core_port_id) # vlan from core self.create_vlan(dp, config_vlan_tagged, config_vlan_untagged, core_vlan, core_port_id) print "core port vlan/group |", "\tvlan #: ", core_vlan, "\tcore port #: ", core_port_id for pc_ in range(0, n_prack * n_lrack * n_server): # loop through all the core ports core_port_ = port_core + pc_ - ( (port_core + pc_ - port_core) % over_subscription ) # physical port number # [group] going out of core # self.create_group_l2_interface(dp, config, core_vlan, core_port_) # [vlan] coming to the core # self.create_vlan(dp, config_vlan_tagged, config_vlan_untagged, core_vlan, core_port_) print "core | ", "\tvlan: ", core_vlan, "\tcore port #: ", core_port_, "\t", socket.inet_ntoa( struct.pack('!L', ip_long + ip_offset_)) print "core | ", "\tvlan: ", core_vlan, "\tcore port #: ", core_port_, "\t", socket.inet_ntoa( struct.pack('!L', ip_10_long + ip_offset_)) # [acl] unicast going out of core to ToRs self.create_acl_unicast( dp, config_acl_unicast, core_vlan, socket.inet_ntoa(struct.pack('!L', ip_long + ip_offset_)), core_port_, default_queue) self.create_acl_unicast( dp, config_acl_unicast, core_vlan, socket.inet_ntoa(struct.pack('!L', ip_10_long + ip_offset_)), core_port_, default_queue) ip_offset_ += 1 # set update the rule for the gateway for pi_ in gateway_port_ip: # [group] self.create_group_l2_interface(dp, config, core_vlan, pi_[0]) # [vlan] self.create_vlan(dp, config_vlan_tagged, config_vlan_untagged, core_vlan, pi_[0]) print "core gateway | ", "\tvlan: ", core_vlan, "\tcore port #: ", pi_[ 0], "\t", pi_[1] # [acl] self.create_acl_unicast(dp, config_acl_unicast, core_vlan, pi_[1], pi_[0], default_queue) self.create_acl_unicast(dp, config_acl_unicast, core_vlan, pi_[2], pi_[0], default_queue) print "default rule: ", "\tport: ", gateway_port_ip[1][0] self.create_acl_unicast_low_wildcard( dp, config_acl_unicast_low_wildcard, core_vlan, gateway_port_ip[1][0], default_queue) # [group] rule flood arp packets @ core core_port_list = list( range(port_core + 0, port_core + n_prack * n_lrack * n_server))[0::over_subscription] for a in gateway_port_ip: core_port_list.append(a[0]) print "core arp: ", "\t", core_port_list self.create_group_l2_flood(dp, config_group_l2_multicast_arp, config_group_l2_multicast_arp_bucket, core_vlan, core_port_list, arp_flood_id, gateway_port_ip=gateway_port_ip) # [acl] rule flood arp packets @ core self.create_acl_arp_flood(dp, config_acl_arp_multicast, core_vlan, default_queue, arp_flood_id) else: pass if 'relay' in self.conf_dict['eps']: for r_d in self.conf_dict['eps']['relay']: if r_d['dpid'] == dpid: print "install relay on dpid %d" % dpid for relay_port in range(r_d['starting'], r_d['starting'] + r_d['num']): # [group] self.create_group_l2_interface(dp, config, r_d['vlanid'], relay_port) # [vlan] self.create_vlan(dp, config_vlan_tagged, config_vlan_untagged, r_d['vlanid'], relay_port) print 'relay |\tvlan: %d, port: %d' % (r_d['vlanid'], relay_port) self.create_acl_unicast_low_port( dp, config_acl_unicast_low_port, r_d['vlanid'], relay_port, relay_port, default_queue) return
def __init__(self, template_dir): self.config_group_l2_interface = ConfigParser.get_config( "%s/%s.json" % (template_dir, "template_group_l2_interface")) self.config_vlan_tagged = ConfigParser.get_config("%s/%s.json" % (template_dir, "template_vlan_tagged")) self.config_vlan_untagged = ConfigParser.get_config("%s/%s.json" % (template_dir, "template_vlan_untagged")) self.config_acl_unicast = ConfigParser.get_config("%s/%s.json" % (template_dir, "template_acl_unicast")) self.config_acl_unicast_low = ConfigParser.get_config("%s/%s.json" % (template_dir, "template_acl_unicast_low")) self.config_acl_unicast_low_wildcard = ConfigParser.get_config( "%s/%s.json" % (template_dir, "template_acl_unicast_low_wildcard")) self.config_acl_unicast_low_port = ConfigParser.get_config( "%s/%s.json" % (template_dir, "template_acl_unicast_low_port")) self.config_acl_arp = ConfigParser.get_config("%s/%s.json" % (template_dir, "template_acl_arp")) self.config_group_l2_multicast_arp = ConfigParser.get_config( "%s/%s.json" % (template_dir, "template_group_l2_multicast")) self.config_group_l2_multicast_arp_bucket = ConfigParser.get_config( "%s/%s.json" % (template_dir, "template_group_l2_multicast_bucket")) self.config_acl_arp_multicast = ConfigParser.get_config( "%s/%s.json" % (template_dir, "template_acl_arp_multicast")) self.config_acl_unicast_eth_port = ConfigParser.get_config( "%s/%s.json" % (template_dir, "template_acl_unicast_eth_port"))