• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python mac_learner.mac_learner函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pyretic.modules.mac_learner.mac_learner函数的典型用法代码示例。如果您正苦于以下问题:Python mac_learner函数的具体用法?Python mac_learner怎么用?Python mac_learner使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了mac_learner函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: example_setup

def example_setup(num_clients=3, num_servers=3):
    ### EXAMPLE PARAMETERS
    # NETWORK BREAKDOWN
    ethernet = [2,3,4,1000]
    ip_core  = [5,6,7,1002]
    gateway  = [1001]

    # SUBNET ADDRESSING
    eth_prefix = '10.0.0.'
    ip_prefix  = '10.0.1.'
    prefix_len = 24
    eth_cidr = eth_prefix + '0/' + str(prefix_len)
    ip_cidr = ip_prefix + '0/' + str(prefix_len)

    # END HOST ADDRESSES
    public_ip = IP('10.0.1.100')
    fake_mac = MAC('BB:BB:BB:BB:BB:BB')
    eth_macs = { IP(eth_prefix+str(i+1)) : MAC('00:00:00:00:00:0'+str(i)) \
                     for i in range(1,1+num_clients) }
    ip_macs = { IP(ip_prefix+str(i+1)) : MAC('00:00:00:00:00:0'+str(i+num_clients)) \
                    for i in range(1,1+num_servers) }
    host_macs = dict(eth_macs.items() + ip_macs.items())
    host_macs.update({IP(public_ip) : fake_mac})

    ### POLICIES FOR THIS EXAMPLE
    eth_pol = mac_learner() 
    ip_pol = mac_learner() 
    gw_pol = gateway_forwarder(eth_cidr,ip_cidr,host_macs)
    
    return ((switch_in(ethernet) & eth_pol) + 
            (switch_in(gateway)  & gw_pol ) +
            (switch_in(ip_core)  & ip_pol ))    
开发者ID:HaiVu,项目名称:pyretic,代码行数:32,代码来源:gateway_3switch_example_basic.py


示例2: main

def main():
    print "load balancer"
    # ips = [IPAddr('10.0.0.1'),IPAddr('10.0.0.2'),IPAddr('10.0.0.3')]
    ips = [IPAddr("10.0.0.3"), IPAddr("10.0.0.4")]
    # macs = [EthAddr("00:00:00:00:00:01"),EthAddr("00:00:00:00:00:02"),EthAddr("00:00:00:00:00:03")]
    macs = [EthAddr("00:00:00:00:00:03"), EthAddr("00:00:00:00:00:04")]
    ports = [10000, 11000]

    rrlb_on_switch = rrlb(2, ips, macs, ports)

    forwardARP = match(ethtype=0x0806)
    forwardICMP = match(ethtype=0x0800, protocol=1)
    return if_(forwardICMP | forwardARP, mac_learner(), rrlb_on_switch >> mac_learner())
开发者ID:whinedo,项目名称:sdnlb,代码行数:13,代码来源:rrlb_mservice.py


示例3: main

def main():
    # Copy the code you used to read firewall-policies.csv from the Pox Firewall assignment
    policyFileContent = open(policy_file)
    # skip first line
    policyFileContent.readline()

    # start with a policy that doesn't match any packets
    not_allowed = none

    while True:
        line = policyFileContent.readline()
        if not line:
            break
        print line
        # info[1] == mac_0, info[2] == mac_1
        info = line.split(',')
        info[2].strip('\n')

        # and add traffic that isn't allowed
        not_allowed = union( [not_allowed, match(dstmac=EthAddr(info[2])) >>
            match(srcmac=EthAddr(info[1]))] )
        not_allowed = union( [not_allowed, match(dstmac=EthAddr(info[1])) >>
            match(srcmac=EthAddr(info[2]))] )

    # express allowed traffic in terms of not_allowed - hint use '~'
    allowed = ~not_allowed

    # and only send allowed traffic to the mac learning (act_like_switch) logic
    return allowed >> mac_learner()
开发者ID:09beeihaq,项目名称:Coursera-SDN-Assignments,代码行数:29,代码来源:pyretic_firewall.py


示例4: main

def main():
    # Copy the code you used to read firewall-policies.csv last week
    acl = []
    # access control list

    csvFile = open(policy_file, "rb")
    inStream = csv.reader(csvFile, delimiter=",")
    for row in inStream:
        acl.append(row)
    acl.pop(0)
    for item in acl:
        item.pop(0)
        # print item

        # start with a policy that doesn't match any packets
    not_allowed = none
    # and add traffic that isn't allowed
    # for <each pair of MAC address in firewall-policies.csv>:
    for item in acl:
        not_allowed = (
            not_allowed
            | match(srcmac=EthAddr(item[0]), dstmac=EthAddr(item[1]))
            | match(srcmac=EthAddr(item[1]), dstmac=EthAddr(item[0]))
        )

    # express allowed traffic in terms of not_allowed - hint use '~'
    # allowed = none
    # for item in acl:
    # allowed = allowed + ~match(srcmac=EthAddr(item[0]),dstmac=EthAddr(item[1])) + ~match(srcmac=EthAddr(item[1]),dstmac=EthAddr(item[0]))

    allowed = ~not_allowed

    # and only send allowed traffic to the mac learning (act_like_switch) logic
    # return allowed >> act_like_switch()
    return allowed >> mac_learner()
开发者ID:ericjpj,项目名称:SDN,代码行数:35,代码来源:pyretic_firewall.py


示例5: main

def main(config, mode, modrepeat=None):
    # Open configuration file
    try:
        fd = open(config, 'r')
    except IOError as err:
        print 'IO Exception: ', err
        sys.exit(1)
        
    # Get mode, check validity
    if mode != 'auto' and mode != 'manual':
        print 'Wrong mode value. Exiting!'
        sys.exit(1)
        
    # Check test mode.
    repeat = 0
    if modrepeat is not None:
        if modrepeat != 0:
            repeat = modrepeat

    # Read configuration file
    content = fd.read()
    fd.close()
    
    # Parse configuration file
    app_to_module_map, app_composition_str = parse_configuration_file(content, mode, repeat)
    
    if len(app_to_module_map) == 0:
        print 'Configuration file seems incorrect. Exiting.'
        sys.exit(1)

    # Run resonance
# return resonance(app_to_module_map, app_composition_str) >> mac_learner()
    return resonance(app_to_module_map, app_composition_str) >> (mac_learner() + scan())
开发者ID:sebasjuancho,项目名称:pyresonance,代码行数:33,代码来源:main.py


示例6: main

def main():
    # Copy the code you used to read firewall-policies.csv from the Pox Firewall assignment
    policies = []

    with open(policy_file, "r") as pf:
        next(pf)
        for line in pf:
            line = line.rstrip()
            tokens = line.split(",")
            mac_0 = MAC(tokens[1])
            mac_1 = MAC(tokens[2])
            policies.append((mac_0, mac_1))

    # start with a policy that doesn't match any packets
    not_allowed = none
    
    # and add traffic that isn't allowed
    for (mac_0, mac_1) in policies:
        not_allowed = union([ (match(srcmac=mac_0) & match(dstmac=mac_1))
                                                   |
                              (match(srcmac=mac_1) & match(dstmac=mac_0))
                                                   |
                              not_allowed
                            ])

    #print not_allowed
    # express allowed traffic in terms of not_allowed - hint use '~'
    allowed = ~not_allowed
    #print allowed

    # and only send allowed traffic to the mac learning (act_like_switch) logic
    return allowed >> mac_learner()
开发者ID:fshewl,项目名称:coursera_SDN,代码行数:32,代码来源:pyretic_firewall.py


示例7: main

def main():
    # Copy the code you used to read firewall-policies.csv from the Pox Firewall assignment
    
    not_allowed=none
    with open(policy_file,'rb') as mycsv:
        reader_macfilter_from_file=csv.DictReader(mycsv)
        for row in reader_macfilter_from_file:
            ssssssss

            not_allowed = union( [not_allowed,union( [match(srcmac=MAC(row['mac_0']),
                                                             dstmac=MAC(row['mac_1'])
                                                             ),
                                                      match(srcmac=MAC(row['mac_1']),
                                                            dstmac=MAC(row['mac_0']))
                                                      ]
                                                     )
                                  ]
                                 )

    # start with a policy that doesn't match any packets
    
    
    # and add traffic that isn't allowed
    
    # express allowed traffic in terms of not_allowed - hint use '~'
    allowed = ~not_allowed
                                             
    #print "not_allowed : "
    #print not_allowed
    #print "allowed :"
    #print allowed
    # and only send allowed traffic to the mac learning (act_like_switch) logic
    return allowed >> mac_learner()
开发者ID:JayantNayak,项目名称:SDN,代码行数:33,代码来源:pyretic_firewall.py


示例8: main

def main():
    # Copy the code you used to read firewall-policies.csv from the Pox Firewall assignment
    fileOpen = open(policy_file)
    fileOpen.readline()
    # start with a policy that doesn't match any packets
    not_allowed = none
    while True:
        readLine = fileOpen.readline()
        if not readLine:
            break
        print readLine
        csvInfo = readLine.split(',')
        csvInfo[2].strip('\n')

        # and add traffic that isn't allowed
        not_allowed = union( [not_allowed, match(dstmac=EthAddr(csvInfo[2])) >>
            match(srcmac=EthAddr(csvInfo[1]))] )
        not_allowed = union( [not_allowed, match(dstmac=EthAddr(csvInfo[1])) >>
            match(srcmac=EthAddr(csvInfo[2]))] )


    # and add traffic that isn't allowed
    # for <each pair of MAC address in firewall-policies.csv>:
    #     not_allowed = union( [
    #         <traffic going in one direction>,
    #         <traffic going in the other direction> ] )

    # express allowed traffic in terms of not_allowed - hint use '~'
    allowed = ~not_allowed

    # and only send allowed traffic to the mac learning (act_like_switch) logic
    return allowed >> mac_learner()
开发者ID:aaronjoel,项目名称:SDN-Software_Defined_Networking,代码行数:32,代码来源:pyretic_firewall.py


示例9: Start

	def Start(self):
		# Handle ARP
		ARPPkt = match(ethtype=ARP_TYPE)

		# Instantiate Firewalls
		AccessControl = self.FW.ApplyFirewall()

		# Instantiate Load Balancer
		LB  = LoadBalancer(self.LB_Device, self.ClientIPs, self.ServerIPs, self.PublicIP)

		self.policy = 	(
					( ARPPkt >> mac_learner() ) +				# ARP - L2 Learning Switches
					( LB >> mac_learner() >> AccessControl ) +	# Load Balancer + Firewall
					Monitor(MonitoringInterval)					# Monitoring
				)

		return self.policy
开发者ID:fp7-netide,项目名称:Usecases,代码行数:17,代码来源:UC1_DC_NetManager.py


示例10: main

def main():
        #logging.basicConfig(filename='log/sdnlb.log', level=logging.INFO,format='%(asctime)s %(message)s', datefmt='%d/%m/%Y %H:%M:%S %p')
        logging.basicConfig(filename='log/sdnlb.log', level=logging.INFO,format='%(asctime)s %(message)s', datefmt='%d/%m/%Y %H:%M:%S %p',filemode='w')
        #logger = logging.getLogger('sdnlblogger')
        #logger = logging.getLogger(__name__)
        logger = logging.getLogger()
        logger.info("shit")
        printConfigInfo(logger)
	algoType = sdnlb_conf.algo
	algo = AlgoFactory.getAlgoInstance(algoType)

	rrlb_sdn = LoadBalancer(sdnlb_conf.switch,sdnlb_conf.sip,sdnlb_conf.smac,algo)

	forwardARP = match(ethtype=0x0806)
	forwardICMP = match(ethtype=0x0800,protocol=1)
	return if_(forwardICMP | forwardARP, mac_learner(), \
			rrlb_sdn >>mac_learner())
开发者ID:whinedo,项目名称:sdnlb,代码行数:17,代码来源:pyretic_lb.py


示例11: main

def main():
  global policy
  global flag

  flag = flag()
  # policy = tag() >> mac_learner() >> (flag + untag()) Don't need tagging
  policy = mac_learner() + flag
  print policy
  return policy
开发者ID:hlzhang,项目名称:pyretic-traceback,代码行数:9,代码来源:dt.py


示例12: main

def main():
    bfs1  = [1,2,3]
    bfs2  = [1,4]
    pol = if_(ARP,arp(),mac_learner())
#    pol = mac_learner()
    return virtualize(
        virtualize(pol,
                   BFS_vdef(from_switches=[1,4])),
        BFS_vdef(from_switches=[1,2,3]))
开发者ID:HaiVu,项目名称:pyretic,代码行数:9,代码来源:layered_bfs.py


示例13: main

def main ():
    HOST, PORT = "localhost", 9002

    my_smart_balancer = smart_balancer()
    server = SmartBalancerTCPServer((HOST,PORT), MyTCPHandler, my_smart_balancer)
    serverThread = threading.Thread(target=start_server, args=(server,))
    serverThread.daemon = True
    serverThread.start()
    
    return my_smart_balancer >> mac_learner()
开发者ID:Nevinli158,项目名称:597E,代码行数:10,代码来源:smart_balencer.py


示例14: example_setup

def example_setup(num_clients=3, num_servers=3):
    ### EXAMPLE PARAMETERS
    # NETWORK BREAKDOWN
    ethernet = [2,3,4,1000]
    ip_core  = [5,6,7,1002]
    gateway  = [1001]

    # SUBNET ADDRESSING
    eth_prefix = '10.0.0.'
    ip_prefix  = '10.0.1.'
    prefix_len = 24
    eth_cidr = eth_prefix + '0/' + str(prefix_len)
    ip_cidr = ip_prefix + '0/' + str(prefix_len)

    # END HOST ADDRESSES
    public_ip = IP('10.0.1.100')
    fake_mac = MAC('BB:BB:BB:BB:BB:BB')
    eth_macs = { IP(eth_prefix+str(i+1)) : MAC('00:00:00:00:00:0'+str(i)) \
                     for i in range(1,1+num_clients) }
    ip_macs = { IP(ip_prefix+str(i+1)) : MAC('00:00:00:00:00:0'+str(i+num_clients)) \
                    for i in range(1,1+num_servers) }
    host_macs = dict(eth_macs.items() + ip_macs.items())
    host_macs.update({IP(public_ip) : fake_mac})

    # PARAMETERS FOR FIREWALL/LOAD BALANCER
    R = [IP(ip_prefix + str(i)) for i in range(2, 2+num_servers)]
    H = {IP(eth_prefix + str(i)) : 0 for i in range(2,2+num_clients)}
    W = {(c,public_ip) for c in H.keys()}

    ### POLICIES FOR THIS EXAMPLE
    eth_pol = mac_learner()
    alb = dynamic(lb)(public_ip,R,H) >> fix_dstmac(ip_macs) 
    afw = if_(ARP,passthrough,dynamic(fw)(W))
    ip_pol = if_(match(srcip=eth_cidr), 
                 afw >> alb, 
                 alb >> afw) >> mac_learner() 
    ip_pol = virtualize(ip_pol,BFS_vdef(name=5,from_switches=ip_core))
    gw_pol = gateway_forwarder(eth_cidr,ip_cidr,host_macs)

    return (switch_in(ethernet)[ eth_pol ] + 
            switch_in(gateway)[  gw_pol  ] +
            switch_in(ip_core)[  ip_pol  ])    
开发者ID:adrian-istrate,项目名称:pyretic,代码行数:42,代码来源:gateway_3switch_example_complex.py


示例15: main

def main(clients, servers):
    from pyretic.modules.mac_learner import mac_learner

    clients   = int(clients)
    servers   = int(servers)

    ip_prefix = "10.0.0."
    public_ip = IP(ip_prefix + "100")
    print("public ip address is %s." % public_ip)
    
    client_ips = [IP(ip_prefix+str(i)) for i in range(1, clients+1)]
    server_ips = [IP(ip_prefix+str(i)) for i in range(1+clients, clients+servers+1)]
    
    return rrlb(client_ips, server_ips, public_ip) >> mac_learner()
开发者ID:YimengZhao,项目名称:netassay,代码行数:14,代码来源:lb.py


示例16: main

def main():
	from pyretic.modules.mac_learner import mac_learner
	from pyretic.examples.Monitor import Monitor
	from pyretic.examples.firewall import firewall_policy
	ARPPkt = match(ethtype=ARP_TYPE)
	Clients = 1
	Servers = 2
	Device_1 = 4
	Device_2 = 3
	PublicIP_1 = IP("10.0.100.1")
	PublicIP_2 = IP("10.0.100.2")
	ClientIPs = [IP("10.0.0.1"), IP("10.0.0.2"), IP("10.0.0.3"), IP("10.0.0.4")]
	ServerIPs_1 = [IP("10.0.0.5"), IP("10.0.0.6")]
	ServerIPs_2 = [IP("10.0.0.7"), IP("10.0.0.8")]
	LB_1 = LoadBalancer(Device_1, ClientIPs, ServerIPs_1, PublicIP_1)
	LB_2 = LoadBalancer(Device_2, ClientIPs, ServerIPs_2, PublicIP_2)
	LB_Monitor_Policy = (
			(ARPPkt >> mac_learner()) +
			( LB_1 >> mac_learner()) +
			( LB_2 >> mac_learner()) +
			Monitor(10)
		)

	return if_(firewall_policy, drop, LB_Monitor_Policy)
开发者ID:Udayan12167,项目名称:pyretic_controller,代码行数:24,代码来源:load_balancer.py


示例17: main

def main(Clients, Servers):
	from pyretic.modules.mac_learner import mac_learner

	Clients   = int(Clients)
	Servers   = int(Servers)
	Device    = 4

	IP_Prefix = "10.0.0."
	PublicIP = IP(IP_Prefix + "100")
	print("Public ip address is %s." % PublicIP)
    
	ClientIPs = [IP(IP_Prefix+str(i)) for i in range(1, Clients+1)]
	ServerIPs = [IP(IP_Prefix+str(i)) for i in range(1+Clients, Clients+Servers+1)]
    
	return LoadBalancer(Device, ClientIPs, ServerIPs, PublicIP) >> mac_learner()
开发者ID:fp7-netide,项目名称:Usecases,代码行数:15,代码来源:LoadBalancer.py


示例18: ApplyFirewall

	def ApplyFirewall(self):
		# Set rules to devices
		ac1 = self.ConfigureFW1()
		ac2 = self.ConfigureFW2()

		# Update block object
		if self.Blocked:
			self.Blocked = self.Blocked | ac1 | ac2
		else:
			self.Blocked = ac1 | ac2

		# The packets tha match Block object are dropped. The rest are forwarded.
		self.Allowed = if_(self.Blocked, drop, mac_learner())

		# Update policy object
		return self.UpdatePolicy()
开发者ID:fp7-netide,项目名称:Usecases,代码行数:16,代码来源:Firewall.py


示例19: main

def main():
    # Copy the code you used to read firewall-policies.csv last week

    # start with a policy that doesn't match any packets
    not_allowed = none
    # and add traffic that isn't allowed
    for rule in rules_lst:
        rule_parts = rule.split(",")
        not_allowed = not_allowed | \ 
            match(srcmac=MAC(rule_parts[1]),dstmac=MAC(rule_parts[2])) | \ 
            match(srcmac=MAC(rule_parts[2]),dstmac=MAC(rule_parts[1])))

    # express allowed traffic in terms of not_allowed - hint use '~'
    allowed = ~not_allowed

    # and only send allowed traffic to the mac learning (act_like_switch) logic
    return allowed >> mac_learner()
开发者ID:redondo-mk,项目名称:coursera,代码行数:17,代码来源:pyretic_firewall.py


示例20: main

def main():
    # Copy the code you used to read firewall-policies.csv from the Pox Firewall assignment

    # start with a policy that doesn't match any packets
    not_allowed = none

    # and add traffic that isn't allowed
    with open(policy_file, 'rb') as f:
        reader = csv.DictReader(f)
        for row in reader:
            not_allowed = not_allowed + match(srcmac=MAC(row['mac_0']), dstmac=MAC(row['mac_1'])) + match(srcmac=MAC(row['mac_1']), dstmac=MAC(row['mac_0']))

    # express allowed traffic in terms of not_allowed - hint use '~'
    allowed = ~not_allowed

    # and only send allowed traffic to the mac learning (act_like_switch) logic
    return allowed >> mac_learner()
开发者ID:ShemamAmir,项目名称:Software-Defined-Networking-002,代码行数:17,代码来源:pyretic_firewall.py



注:本文中的pyretic.modules.mac_learner.mac_learner函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python pyrfc3339.generate函数代码示例发布时间:2022-05-27
下一篇:
Python kd_tree.resample_nearest函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap