Esempio n. 1
0
def build_inbound_rules_for(participant_id, in_policies, ss_instance, final_switch):
    "Given a subset of inbound policies, return all the resulting rules."

    rules = []


    for policy in in_policies:
        if "fwd" not in policy["action"]:
            continue

        port_num = policy["action"]["fwd"]

        # match on the next-hop
        vmac_bitmask = vmac_next_hop_mask(ss_instance)
        vmac = vmac_next_hop_match(participant_id, ss_instance)


        match_args = policy["match"]
        match_args["eth_dst"] = (vmac, vmac_bitmask)


        port_num = policy["action"]["fwd"]
        new_vmac = vmac_part_port_match(participant_id, port_num, ss_instance)


        actions = {"set_eth_dst":new_vmac, "fwd":[final_switch]}

        rule = {"rule_type":"inbound", "priority":INBOUND_HIT_PRIORITY,
                "match":match_args, "action":actions, "mod_type":"insert",
                "cookie":(policy["cookie"],2**16-1)}

        rules.append(rule)

    return rules
Esempio n. 2
0
def build_inbound_rules_for(participant_id, in_policies, ss_instance, final_switch):
    "Given a subset of inbound policies, return all the resulting rules."

    rules = []

    for policy in in_policies:
        if "fwd" not in policy["action"]:
            continue

        port_num = policy["action"]["fwd"]

        # match on the next-hop
        vmac_bitmask = vmac_next_hop_mask(ss_instance)
        vmac = vmac_next_hop_match(participant_id, ss_instance)

        match_args = policy["match"]
        match_args["eth_dst"] = (vmac, vmac_bitmask)

        port_num = policy["action"]["fwd"]
        new_vmac = vmac_part_port_match(participant_id, port_num, ss_instance)

        actions = {"set_eth_dst": new_vmac, "fwd": [final_switch]}

        rule = {
            "rule_type": "inbound",
            "priority": INBOUND_HIT_PRIORITY,
            "match": match_args,
            "action": actions,
            "mod_type": "insert",
            "cookie": (policy["cookie"], 2 ** 16 - 1),
        }

        rules.append(rule)

    return rules
    def process_arp_request(self, part_mac, vnh):
        vmac = ""
        if self.cfg.isSupersetsMode():
            vmac = self.supersets.get_vmac(self, vnh)
        else:
            vmac = "whoa"  # MDS vmac goes here

        arp_responses = list()

        # if this is gratuitous, send a reply to the part's ID
        if part_mac is None:
            gratuitous = True
            # set fields appropriately for gratuitous arps
            i = 0
            for port in self.cfg.ports:
                eth_dst = vmac_part_port_match(self.id, i, self.supersets,
                                               False)
                arp_responses.append({
                    'SPA': vnh,
                    'TPA': vnh,
                    'SHA': vmac,
                    'THA': vmac,
                    'eth_src': vmac,
                    'eth_dst': eth_dst
                })
                i += 1

        else:  # if it wasn't gratuitous
            gratuitous = False
            # dig up the IP of the target participant
            for port in self.cfg.ports:
                if part_mac == port["MAC"]:
                    part_ip = port["IP"]
                    break

            # set field appropriately for arp responses
            arp_responses.append({
                'SPA': vnh,
                'TPA': part_ip,
                'SHA': vmac,
                'THA': part_mac,
                'eth_src': vmac,
                'eth_dst': part_mac
            })

        if gratuitous:
            self.logger.debug("Sending Gratuitious ARP: " + str(arp_responses))
        else:
            self.logger.debug("Sending ARP Response: " + str(arp_responses))

        for arp_response in arp_responses:
            arp_response['msgType'] = 'garp'
            self.arp_client.send(arp_response)
Esempio n. 4
0
    def process_arp_request(self, part_mac, vnh):
        vmac = ""
        if self.cfg.isSupersetsMode():
            vmac = self.supersets.get_vmac(self, vnh)
        else:
            vmac = "whoa" # MDS vmac goes here

        arp_responses = list()

        # if this is gratuitous, send a reply to the part's ID
        if part_mac is None:
            gratuitous = True
            # set fields appropriately for gratuitous arps
            i = 0
            for port in self.cfg.ports:
                eth_dst = vmac_part_port_match(self.id, i, self.supersets, False)
                arp_responses.append({'SPA': vnh, 'TPA': vnh,
                                   'SHA': vmac, 'THA': vmac,
                                   'eth_src': vmac, 'eth_dst': eth_dst})
                i += 1

        else: # if it wasn't gratuitous
            gratuitous = False
            # dig up the IP of the target participant
            for port in self.cfg.ports:
                if part_mac == port["MAC"]:
                    part_ip = port["IP"]
                    break

            # set field appropriately for arp responses
            arp_responses.append({'SPA': vnh, 'TPA': part_ip,
                        'SHA': vmac, 'THA': part_mac,
                        'eth_src': vmac, 'eth_dst': part_mac})

        if gratuitous:
            self.logger.debug("Sending Gratuitious ARP: "+str(arp_responses))
        else:
            self.logger.debug("Sending ARP Response: "+str(arp_responses))

        for arp_response in arp_responses:
            arp_response['msgType'] = 'garp'
            self.arp_client.send(arp_response)