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


Python policy.Policy方法代码示例

本文整理汇总了Python中policy.Policy方法的典型用法代码示例。如果您正苦于以下问题:Python policy.Policy方法的具体用法?Python policy.Policy怎么用?Python policy.Policy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在policy的用法示例。


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

示例1: test_harvest_ARP

# 需要导入模块: import policy [as 别名]
# 或者: from policy import Policy [as 别名]
def test_harvest_ARP():
    """
    Test harvesting identity metadata from an IPv4 ARP reply.
    """
    #*** Instantiate flow, policy and identities objects:
    flow = flows_module.Flow(config)
    policy = policy_module.Policy(config)
    identities = identities_module.Identities(config, policy)

    #*** Server ARP Reply:
    flow.ingest_packet(DPID1, INPORT1, pkts_arp.RAW[1], datetime.datetime.now())
    identities.harvest(pkts_arp.RAW[1], flow.packet)
    result_identity = identities.findbymac(pkts_arp.ETH_SRC[1])

    assert result_identity['mac_address'] == pkts_arp.ETH_SRC[1]
    assert result_identity['ip_address'] == '10.1.0.2' 
开发者ID:mattjhayes,项目名称:nmeta,代码行数:18,代码来源:test_identities.py

示例2: test_harvest_DNS

# 需要导入模块: import policy [as 别名]
# 或者: from policy import Policy [as 别名]
def test_harvest_DNS():
    """
    Test harvesting identity metadata from DNS packets
    """
    #*** Instantiate flow, policy and identities objects:
    flow = flows_module.Flow(config)
    policy = policy_module.Policy(config)
    identities = identities_module.Identities(config, policy)

    #*** DNS packet 1 (NAME to CNAME, then second answer with IP for CNAME):
    flow.ingest_packet(DPID1, INPORT1, pkts_dns.RAW[1], datetime.datetime.now())
    identities.harvest(pkts_dns.RAW[1], flow.packet)
    result_identity = identities.findbyservice(pkts_dns.DNS_NAME[1])
    assert result_identity['service_name'] == pkts_dns.DNS_NAME[1]
    assert result_identity['service_alias'] == pkts_dns.DNS_CNAME[1]
    result_identity = identities.findbyservice(pkts_dns.DNS_CNAME[1])
    assert result_identity['service_name'] == pkts_dns.DNS_CNAME[1]
    assert result_identity['ip_address'] == pkts_dns.DNS_IP[1] 
开发者ID:mattjhayes,项目名称:nmeta,代码行数:20,代码来源:test_identities.py

示例3: test_custom_classifiers

# 需要导入模块: import policy [as 别名]
# 或者: from policy import Policy [as 别名]
def test_custom_classifiers():
    """
    Check deduplicated list of custom classifiers works
    """
    #*** Instantiate policy, specifying
    #*** a particular main_policy file to use that has no custom classifiers:
    policy = policy_module.Policy(config,
                            pol_dir_default="config/tests/regression",
                            pol_dir_user="config/tests/regression",
                            pol_filename="main_policy_regression_static.yaml")
    assert policy.tc_rules.custom_classifiers == []

    #*** Instantiate policy, specifying
    #*** a custom statistical main_policy file to use that has a
    #*** custom classifier:
    policy = policy_module.Policy(config,
                        pol_dir_default="config/tests/regression",
                        pol_dir_user="config/tests/foo",
                        pol_filename="main_policy_regression_statistical.yaml")
    assert policy.tc_rules.custom_classifiers == ['statistical_qos_bandwidth_1'] 
开发者ID:mattjhayes,项目名称:nmeta,代码行数:22,代码来源:test_policy.py

示例4: test_portsets_get_port_set

# 需要导入模块: import policy [as 别名]
# 或者: from policy import Policy [as 别名]
def test_portsets_get_port_set():
    """
    Test that get_port_set returns correct port_set name
    """
    #*** Instantiate Policy class instance:
    policy = policy_module.Policy(config,
                            pol_dir_default="config/tests/regression",
                            pol_dir_user="config/tests/regression",
                            pol_filename="main_policy_regression_static.yaml")

    #*** Positive matches:
    assert policy.port_sets.get_port_set(255, 5, 0) == "port_set_location_internal"
    assert policy.port_sets.get_port_set(1, 6, 0) == "port_set_location_external"

    #*** Shouldn't match:
    assert policy.port_sets.get_port_set(1234, 5, 0) == "" 
开发者ID:mattjhayes,项目名称:nmeta,代码行数:18,代码来源:test_policy.py

示例5: test_portset_is_member

# 需要导入模块: import policy [as 别名]
# 或者: from policy import Policy [as 别名]
def test_portset_is_member():
    """
    Test that the PortSet class method is_member works correctly
    """
    #*** Instantiate Policy class instance:
    policy = policy_module.Policy(config,
                            pol_dir_default="config/tests/regression",
                            pol_dir_user="config/tests/regression",
                            pol_filename="main_policy_regression_static.yaml")

    #*** Members:
    assert policy.port_sets.port_sets_list[0].is_member(255, 5, 0) == 1
    assert policy.port_sets.port_sets_list[0].is_member(1, 2, 0) == 1
    #*** Not members:
    assert policy.port_sets.port_sets_list[0].is_member(255, 4, 0) == 0
    assert policy.port_sets.port_sets_list[0].is_member(256, 5, 0) == 0
    assert policy.port_sets.port_sets_list[0].is_member(255, 5, 1) == 0 
开发者ID:mattjhayes,项目名称:nmeta,代码行数:19,代码来源:test_policy.py

示例6: test_validate_location

# 需要导入模块: import policy [as 别名]
# 或者: from policy import Policy [as 别名]
def test_validate_location():
    """
    Test validation that a location string appears as a location in policy
    """
    policy = policy_module.Policy(config,
                            pol_dir_default="config/tests/regression",
                            pol_dir_user="config/tests/foo",
                            pol_filename="main_policy_regression_static.yaml")
    #*** Good location strings:
    assert policy_module.validate_location(logger, 'internal', policy) == True
    assert policy_module.validate_location(logger, 'external', policy) == True

    #*** Invalid location strings:
    with pytest.raises(SystemExit) as exit_info:
        policy_module.validate_location(logger, 'foo', policy)
    with pytest.raises(SystemExit) as exit_info:
        policy_module.validate_location(logger, '', policy) 
开发者ID:mattjhayes,项目名称:nmeta,代码行数:19,代码来源:test_policy.py

示例7: test_location_check

# 需要导入模块: import policy [as 别名]
# 或者: from policy import Policy [as 别名]
def test_location_check():
    """
    Test the check method of the Location class

    Check a dpid/port to see if it is part of this location
    and if so return the string name of the location otherwise
    return empty string
    """
    #*** Instantiate Policy class instance:
    policy = policy_module.Policy(config,
                            pol_dir_default="config/tests/regression",
                            pol_dir_user="config/tests/foo",
                            pol_filename="main_policy_regression_static.yaml")

    #*** Test against 'internal' location:
    assert policy.locations.locations_list[0].check(1, 1) == 'internal'
    assert policy.locations.locations_list[0].check(1, 6) == ''
    assert policy.locations.locations_list[0].check(56, 1) == ''
    assert policy.locations.locations_list[0].check(255, 3) == 'internal'

    #*** Test against 'external' location:
    assert policy.locations.locations_list[1].check(1, 6) == 'external'
    assert policy.locations.locations_list[1].check(1, 1) == '' 
开发者ID:mattjhayes,项目名称:nmeta,代码行数:25,代码来源:test_policy.py

示例8: test_locations_get_location

# 需要导入模块: import policy [as 别名]
# 或者: from policy import Policy [as 别名]
def test_locations_get_location():
    """
    Test the get_location method of the Locations class
    """
    #*** Instantiate Policy class instance:
    policy = policy_module.Policy(config,
                            pol_dir_default="config/tests/regression",
                            pol_dir_user="config/tests/foo",
                            pol_filename="main_policy_regression_static.yaml")

    #*** Test against 'internal' location:
    assert policy.locations.get_location(1, 1) == 'internal'
    assert policy.locations.get_location(255, 3) == 'internal'
    assert policy.locations.get_location(1, 66) == 'internal'

    #*** Test against 'external' location:
    assert policy.locations.get_location(1, 6) == 'external'
    assert policy.locations.get_location(255, 4) == 'external'

    #*** Test against no match to default 'unknown' location:
    assert policy.locations.get_location(1, 7) == 'unknown'
    assert policy.locations.get_location(1234, 5) == 'unknown' 
开发者ID:mattjhayes,项目名称:nmeta,代码行数:24,代码来源:test_policy.py

示例9: test_get_dns_ip

# 需要导入模块: import policy [as 别名]
# 或者: from policy import Policy [as 别名]
def test_get_dns_ip():
    """
    Test looking up a DNS CNAME to get an IP address
    """
    #*** Instantiate flow, policy and identities objects:
    flow = flows_module.Flow(config)
    policy = policy_module.Policy(config)
    identities = identities_module.Identities(config, policy)

    #*** DNS packet 1 (NAME to CNAME, then second answer with IP for CNAME):
    flow.ingest_packet(DPID1, INPORT1, pkts_dns.RAW[1], datetime.datetime.now())
    identities.harvest(pkts_dns.RAW[1], flow.packet)

    logger.debug("Testing lookup of CNAME=%s", pkts_dns.DNS_CNAME[1])
    result_ip = api.get_dns_ip(pkts_dns.DNS_CNAME[1])
    assert result_ip == pkts_dns.DNS_IP[1] 
开发者ID:mattjhayes,项目名称:nmeta,代码行数:18,代码来源:test_api_external.py

示例10: get_policy

# 需要导入模块: import policy [as 别名]
# 或者: from policy import Policy [as 别名]
def get_policy(self):
    if self.recurrent:
      cls = policy.Policy
    else:
      cls = policy.MLPPolicy
    return cls(self.env_spec, self.internal_dim,
               fixed_std=self.fixed_std,
               recurrent=self.recurrent,
               input_prev_actions=self.input_prev_actions) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:11,代码来源:trainer.py

示例11: test_check_tc_rule

# 需要导入模块: import policy [as 别名]
# 或者: from policy import Policy [as 别名]
def test_check_tc_rule():
    #*** Instantiate classes:
    policy = policy_module.Policy(config,
                            pol_dir_default="config/tests/regression",
                            pol_dir_user="config/tests/foo",
                            pol_filename="main_policy_regression_static.yaml")
    flow = flows_module.Flow(config)
    ident = identities.Identities(config, policy)

    #*** Test Flow 1 Packet 1 (Client TCP SYN):
    # 10.1.0.1 10.1.0.2 TCP 74 43297 > http [SYN]
    flow.ingest_packet(DPID1, INPORT1, pkts.RAW[0], datetime.datetime.now())
    #*** Set policy.pkt as work around for not calling parent method that sets it:
    policy.pkt = flow.packet

    #*** main_policy_regression_static.yaml shouldn't match HTTP (rule 0):
    tc_rules = policy_module.TCRules(policy)
    tc_rule = policy_module.TCRule(tc_rules, policy, 0)
    tc_rule_result = tc_rule.check_tc_rule(flow, ident)
    assert tc_rule_result.match == False
    assert tc_rule_result.continue_to_inspect == False
    assert tc_rule_result.classification_tag == ""
    assert tc_rule_result.actions == {}


    #*** main_policy_regression_static_3.yaml should match HTTP (rule 0):
    policy = policy_module.Policy(config,
                            pol_dir_default="config/tests/regression",
                            pol_dir_user="config/tests/foo",
                            pol_filename="main_policy_regression_static_3.yaml")
    ident = identities.Identities(config, policy)
    tc_rules = policy_module.TCRules(policy)
    tc_rule = policy_module.TCRule(tc_rules, policy, 0)
    tc_rule_result = tc_rule.check_tc_rule(flow, ident)
    assert tc_rule_result.match == True
    assert tc_rule_result.continue_to_inspect == False
    assert tc_rule_result.classification_tag == "Constrained Bandwidth Traffic"
    assert tc_rule_result.actions == {'qos_treatment': 'constrained_bw',
                                   'set_desc': 'Constrained Bandwidth Traffic'}

    # TBD - more 
开发者ID:mattjhayes,项目名称:nmeta,代码行数:43,代码来源:test_policy.py

示例12: test_qos

# 需要导入模块: import policy [as 别名]
# 或者: from policy import Policy [as 别名]
def test_qos():
    """
    Test the assignment of QoS queues based on a qos_treatment action
    """
    #*** Instantiate policy, specifying
    #*** a particular main_policy file to use that has no custom classifiers:
    policy = policy_module.Policy(config,
                            pol_dir_default="config/tests/regression",
                            pol_dir_user="config/tests/foo",
                            pol_filename="main_policy_regression_static.yaml")
    assert policy.qos('default_priority') == 0
    assert policy.qos('constrained_bw') == 1
    assert policy.qos('high_priority') == 2
    assert policy.qos('low_priority') == 3
    assert policy.qos('foo') == 0 
开发者ID:mattjhayes,项目名称:nmeta,代码行数:17,代码来源:test_policy.py

示例13: test_get_host_by_ip

# 需要导入模块: import policy [as 别名]
# 或者: from policy import Policy [as 别名]
def test_get_host_by_ip():
    """
    Test get_host_by_ip
    """
    #*** Instantiate flow, policy and identities objects:
    flow = flows_module.Flow(config)
    policy = policy_module.Policy(config)
    identities = identities_module.Identities(config, policy)

    #*** Ingest ARP reply for MAC of pc1 so can ref later:
    flow.ingest_packet(DPID1, INPORT1, pkts_arp.RAW[3], datetime.datetime.now())
    identities.harvest(pkts_arp.RAW[3], flow.packet)

    #*** Ingest LLDP from pc1
    flow.ingest_packet(DPID1, INPORT1, pkts_lldp.RAW[0], datetime.datetime.now())
    identities.harvest(pkts_lldp.RAW[0], flow.packet)

    #*** Call the get_host_by_ip:
    get_host_by_ip_result = api.get_host_by_ip('10.1.0.1')

    logger.debug("get_host_by_ip_result=%s", get_host_by_ip_result)

    assert get_host_by_ip_result == 'pc1.example.com'

    #*** Test DHCP to host by IP

    #*** Client to Server DHCP Request:
    flow.ingest_packet(DPID1, INPORT1, pkts_dhcp.RAW[2], datetime.datetime.now())
    identities.harvest(pkts_dhcp.RAW[2], flow.packet)

    #*** Server to Client DHCP ACK:
    flow.ingest_packet(DPID1, INPORT2, pkts_dhcp.RAW[3], datetime.datetime.now())
    identities.harvest(pkts_dhcp.RAW[3], flow.packet)

    #*** Call the get_host_by_ip:
    get_host_by_ip_result = api.get_host_by_ip('10.1.0.1')

    logger.debug("get_host_by_ip_result=%s", get_host_by_ip_result)

    assert get_host_by_ip_result == 'pc1' 
开发者ID:mattjhayes,项目名称:nmeta,代码行数:42,代码来源:test_api_external.py

示例14: test_get_classification

# 需要导入模块: import policy [as 别名]
# 或者: from policy import Policy [as 别名]
def test_get_classification():
    """
    Test get_classification which takes a flow_hash
    and return a dictionary of a classification object
    for the flow_hash (if found), otherwise
    a dictionary of an empty classification object.
    """
    #*** Instantiate flow, policy and identities objects:
    flow = flows_module.Flow(config)
    policy = policy_module.Policy(config)
    ident = identities_module.Identities(config, policy)

    #*** Initial main_policy that matches tcp-80:
    policy = policy_module.Policy(config,
                        pol_dir_default="config/tests/regression",
                        pol_dir_user="config/tests/foo",
                        pol_filename="main_policy_regression_static_3.yaml")

    #*** Ingest Flow 1 Packet 0 (Client TCP SYN):
    flow.ingest_packet(DPID1, INPORT1, pkts.RAW[0], datetime.datetime.now())
    #*** Classify the packet:
    policy.check_policy(flow, ident)

    logger.debug("pkt0 flow classification is %s", flow.classification.dbdict())

    #*** Write classification result to classifications collection:
    flow.classification.commit()

    #*** Retrieve classification via get_classification and check results:
    clasfn_result = api.get_classification(flow.classification.flow_hash)
    assert clasfn_result['classified'] ==  1
    assert clasfn_result['classification_tag'] ==  "Constrained Bandwidth Traffic"
    assert clasfn_result['actions']['set_desc'] == "Constrained Bandwidth Traffic"
    assert clasfn_result['actions']['qos_treatment'] == "constrained_bw" 
开发者ID:mattjhayes,项目名称:nmeta,代码行数:36,代码来源:test_api_external.py

示例15: main

# 需要导入模块: import policy [as 别名]
# 或者: from policy import Policy [as 别名]
def main(_):
  # preprocess
  conf.observation_dims = eval(conf.observation_dims)

  # start
  gpu_options = tf.GPUOptions(
      per_process_gpu_memory_fraction=calc_gpu_fraction(conf.gpu_fraction))

  dataset = data_loader(conf.source_path, conf.target_path)

  with tf.Session(config=tf.ConfigProto(gpu_options=gpu_options)) as sess:
    env = Curve()

    pred_network = CNN(sess=sess,
                       observation_dims=conf.observation_dims,
                       name='pred_network', 
		       trainable=True)

    policy = Policy(sess=sess, 
		    pred_network=pred_network,
		    env=env,
		    dataset=dataset,
		    conf=conf)

    if conf.is_train:
        policy.train()
    else:
	policy.test(conf.test_image_path) 
开发者ID:chingyaoc,项目名称:photo-editing-tensorflow,代码行数:30,代码来源:main.py


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