当前位置: 首页>>代码示例>>Python>>正文


Python mac_learner.mac_learner函数代码示例

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


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


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