vnh.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:swift 作者: nsg-ethz 项目源码 文件源码
def insert_primary_rules(self, primary_ip):
        primary_tag = self.tag_dic[primary_ip]
        tmp_mac = bin(primary_tag)[2:]
        tmp_mac = tmp_mac.zfill(self.nexthops_nb_bits)

        tmp_mac = string.ljust(tmp_mac, 48, '0')

        bitmask = string.ljust('', self.nexthops_nb_bits, '1')
        bitmask = string.ljust(bitmask, 48, '0')

        try:
            real_mac = self.mapping_real[primary_ip][0]
            outport = self.mapping_real[primary_ip][1]
        except KeyError:
            real_mac = 'unknown'
            outport = 'unknown'

        # Binary to Hexadecimal conversion
        tmp_mac = hex(int(tmp_mac, 2))[2:].zfill(12)
        bitmask = hex(int(bitmask, 2))[2:].zfill(12)

        tmp_mac = ':'.join(s.encode('hex') for s in tmp_mac.decode('hex'))
        bitmask = ':'.join(s.encode('hex') for s in bitmask.decode('hex'))

        self.fd_rules.write('ovs-ofctl add-flow s1 priority=10,dl_dst='+tmp_mac+'/'+bitmask+',actions=mod_dl_dst:'+real_mac+',output:'+outport+'\n')
        os.system('ovs-ofctl add-flow s1 priority=10,dl_dst='+tmp_mac+'/'+bitmask+',actions=mod_dl_dst:'+real_mac+',output:'+outport)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号