def install_simple_flows(): count = 0 for h in ports: # for each high-capacity source host for sw in ports[h]: # for each switch in the tree # group entry newgid = get_next_gid(sw) g = GroupEntry(dpids[sw]["id"], newgid, "ALL") i = 0 for p in ports[h][sw]: # for each switch port in the tree g.addBucket() g.addAction(i, "OUTPUT", port=p) i += 1 g.install() count += 1 # flow entry (also match on in_port for reverse path check) f = FlowEntry(dpids[sw]["id"]) f.addMatch("in_port", reverse_path_port(hosts[h], sw)) f.addMatch("dl_type", 0x800) f.addMatch("nw_src", hosts[h]['ip']) f.addMatch("nw_dst", MCAST_ADDR) f.addAction("GROUP", group_id=newgid) f.install() count += 1 increment_mcast_addr() return count
def install_lq_flows(): for t in ports_lq: # for each transcoder as source for sw in ports_lq[t]: # for each switch in the tree # group entry newgid = get_next_gid(sw) g = GroupEntry(dpids[sw]["id"], newgid, "ALL") i = 0 for p in ports_lq[t][sw]: # for each switch port in the tree g.addBucket() g.addAction(i, "OUTPUT", port=p) i += 1 g.install() # flow entry (also match on in_port for reverse path check) # do not install on transcoder switch, tos is not set by T if not sw == tees[t]['switch']: f = FlowEntry(dpids[sw]["id"]) f.addMatch("in_port", reverse_path_port(tees[t], sw)) f.addMatch("dl_type", 0x800) f.addMatch("ip_dscp", DSCP_VALUE) f.addMatch("nw_src", tees[t]['ip']) f.addMatch("nw_dst", MCAST_ADDR) f.addAction("GROUP", group_id=newgid) f.install() # set ip dscp when coming from T # the last group added to T's switch refers to the low-capacity tree tsw = tees[t]['switch'] lastgid = gid[tsw] - 1 # flow entry (match on in_port, not nw_src, because original IP address # should be kept) f = FlowEntry(dpids[tsw]["id"]) f.addMatch("in_port", tees[t]['port']) f.addMatch("dl_type", 0x800) f.addMatch("nw_dst", MCAST_ADDR) f.addAction("SET_FIELD", field="ip_dscp", value=DSCP_VALUE) f.addAction("GROUP", group_id=lastgid) f.install()
def install_branch_aware_flows(sh, dhs): global switch_usage count = 0 branch_node = {} degree = {} installed = {} branch_node_sw = {} src = hosts[sh]['switch'] for dh in dhs: branch_node[dh] = None for sw in switches.keys(): branch_node_sw[sw] = 0 for dh in dhs: dst = hosts[dh]['switch'] cur = dst pre = cur first = 1 while cur is not None: if (len(switch_usage[cur]) > 1): if (first is not 1): port = switches[cur][pre]["port"] branch_node[dh] = cur, port break elif (first is 1): break elif (len(switch_usage[cur]) == 1): pre = cur cur = sp[src][cur] first = 0 for dh in dhs: if branch_node[dh] is not None: branch_node_sw[branch_node[dh][0]] = 1 for h in ports: for sw in ports[h]: degree[sw] = len(ports[h][sw]) + 1 installed[sw] = 0 for h in ports: # for each high-capacity source host for sw in ports[h]: # for each switch in the tree if (len(switch_usage[sw]) > 1): # group entry newgid = get_next_gid(sw) g = GroupEntry(dpids[sw]["id"], newgid, "ALL") i = 0 for p in ports[h][sw]: # for each switch port in the tree g.addBucket() g.addAction(i, "OUTPUT", port=p) i += 1 g.install() count += 1 dpids[sw]["capacity"] = dpids[sw]["capacity"] - 1 # flow entry (also match on in_port for reverse path check) f = FlowEntry(dpids[sw]["id"]) f.addMatch("in_port", reverse_path_port(hosts[h], sw)) f.addMatch("dl_type", 0x800) f.addMatch("nw_src", hosts[h]['ip']) f.addMatch("nw_dst", MCAST_ADDR) f.addAction("GROUP", group_id=newgid) f.install() count += 1 dpids[sw]["capacity"] = dpids[sw]["capacity"] - 1 for h in ports: for dh in dhs: if branch_node[dh] is not None: sw, p = branch_node[dh] if sw is not None: f = FlowEntry(dpids[sw]["id"]) f.addMatch("in_port", reverse_path_port(hosts[h], sw)) f.addMatch("dl_type", 0x800) f.addMatch("nw_dst", MCAST_ADDR) f.addAction("SET_FIELD", field="ipv4_dst", value=hosts[dh]['ip']) f.addAction("OUTPUT", port=p) f.install() count += 1 dpids[sw]["capacity"] = dpids[sw]["capacity"] - 1 for h in ports: i = 0 for sw in ports[h]: if (len(switch_usage[sw]) == 1): f = FlowEntry(dpids[sw]["id"]) f.addMatch("in_port", reverse_path_port(hosts[h], sw)) f.addMatch("dl_type", 0x800) f.addMatch("nw_src", hosts[h]['ip']) f.addMatch("nw_dst", hosts[switch_usage[sw][0]]['ip']) for p in ports[h][sw]: f.addAction("OUTPUT", port=p) f.install() i += 1 increment_mcast_addr() return count