def interface_configuration_update(
    device_name,
    interface_name,
    description=None,
    address=None,
    netmask=None,
    active='act',
    shutdown=False
):
    '''Update the configuration of the specified interface of the specified device.
    
    The outcome is undefined if the specified device is not connected. 
    '''
    fields = {"interface-name": interface_name}
    if shutdown:
        fields["shutdown"] = ""
    if active:
        fields["active"] = active
    if description:
        fields["description"] = description
    if address or netmask:
        primary = {}
        if address:
            primary["address"] = address
        if netmask:
            primary["netmask"] = netmask
        #TODO test if address is IPv4 or IPv6
        fields["Cisco-IOS-XR-ipv4-io-cfg:ipv4-network"] = {
            "addresses": {
                "primary": primary
            }
        } 
    request_content = {"interface-configuration": [fields]}
    url_params = {'node-id' : device_name, 'active' : active, 'interface-id' : interface_name}
    odl_http_put(_configuration_uni_url_template, url_params, 'application/json', request_content, expected_status_code=200)
def Add_flow(VIP_Hosts):
    for (k, host) in VIP_Hosts.items():
        priority = str(2001)
        go_flow_id = str(1)
        come_flow_id = str(2)

        host_access_switch = host["host_access_switch"]
        host_access_port = host["host_access_port"]

        host_ipv4 = host["ip"]
        print host_ipv4
        remote_ipv4 = Remote["YouTube"]
        cache_mac = Cache[1]["mac"]
        cache_ipv4 = Cache[1]["ip"]
        cache_access_port = Cache[1]["cache_access_port"]

        # redirect to cache
        response = odl_http_put(
            url_suffix=
            "config/opendaylight-inventory:nodes/node/{openflow_1}/table/0/flow/{flow_id}",
            url_params={
                "openflow_1": host_access_switch,
                "flow_id": go_flow_id
            },
            contentType="application/json",
            content=FlowMod_Change_DST(host_ipv4,
                                       remote_ipv4,
                                       cache_mac,
                                       cache_ipv4,
                                       prioritys=priority,
                                       flowId=go_flow_id,
                                       outPort=cache_access_port),
            expected_status_code=200)
        print "go:", response
        # redirect to host
        response = odl_http_put(
            url_suffix=
            "config/opendaylight-inventory:nodes/node/{openflow_1}/table/0/flow/{flowId}",
            url_params={
                "openflow_1": host_access_switch,
                "flowId": come_flow_id
            },
            contentType="application/json",
            content=FlowMod_Change_SRC(cache_ipv4,
                                       host_ipv4,
                                       GW_MAC,
                                       remote_ipv4,
                                       prioritys=priority,
                                       flowId=come_flow_id,
                                       outPort=host_access_port),
            expected_status_code=200)
        print "come:", response
def interface_configuration_update(
    node_id, interface_name, description, address, netmask, active="act", shutdown=False
):
    """Update the configuration of the specified interface of the specified device."""
    url_params = {
        "config": "config",
        "topology-id": "topology-netconf",
        "node-id": node_id,
        "active": active,
        "interface-name": interface_name,
    }
    request_content = interfaceRequestJSON(active, netmask, address, interface_name, description, shutdown)
    odl_http_put(
        _url_interface_configuration, url_params, "application/json", request_content, expected_status_code=200
    )
def interface_toggle(node_id, interface_name, shutdown):
    """Toggle the state of the specified interface of the specified device."""
    request_url = _url_interface_configuration.format(**{'config': 'config', 
                                                         'topology-id': 'topology-netconf',
                                                         'node-id': node_id,
                                                         'active': 'act',
                                                         'interface-name': quote_plus(interface_name),
                                                         })
    ifcfg = interface_configuration(node_id, interface_name)
    if shutdown:
        ifcfg['interface-configuration'][0]['shutdown'] = ""
    else: # bring back up
        if 'shutdown' in ifcfg['interface-configuration'][0]:
            ifcfg['interface-configuration'][0].pop('shutdown')
    request_content = json.dumps(ifcfg)
    odl_http_put(request_url, 'application/json', request_content, expected_status_code=200)
def Add_flow(VIP_Hosts):
    for (k,host) in VIP_Hosts.items():
        priority = str(2001)  
        go_flow_id = str(1)
        come_flow_id= str(2)
        
        host_access_switch = host["host_access_switch"]
        host_access_port = host["host_access_port"]
        
        host_ipv4 = host["ip"]
        print host_ipv4
        remote_ipv4 = Remote["YouTube"]
        cache_mac=Cache[1]["mac"]
        cache_ipv4 = Cache[1]["ip"]
        cache_access_port = Cache[1]["cache_access_port"]
        
        # redirect to cache    
        response = odl_http_put(
                                url_suffix = "config/opendaylight-inventory:nodes/node/{openflow_1}/table/0/flow/{flow_id}",
                                url_params = {"openflow_1" : host_access_switch, "flow_id" : go_flow_id},
                                contentType = "application/json",
                                content = FlowMod_Change_DST(host_ipv4,
                                                             remote_ipv4,
                                                             cache_mac,
                                                             cache_ipv4,
                                                             prioritys=priority, 
                                                             flowId=go_flow_id, 
                                                             outPort=cache_access_port),
                                expected_status_code = 200
                                )
        print "go:",response
        # redirect to host
        response = odl_http_put(
                                url_suffix = "config/opendaylight-inventory:nodes/node/{openflow_1}/table/0/flow/{flowId}",
                                url_params = {"openflow_1" : host_access_switch, "flowId" : come_flow_id},
                                contentType = "application/json",
                                content = FlowMod_Change_SRC(cache_ipv4,
                                                             host_ipv4,
                                                             GW_MAC,
                                                             remote_ipv4,
                                                             prioritys=priority, 
                                                             flowId=come_flow_id, 
                                                             outPort=host_access_port),
                                expected_status_code = 200
                                )
        print "come:",response
def pushFlow(priority, ethType, ipv4Src, ipv4Dst, flowId, nodeId, outPort):
    return odl_http_put(
    url_suffix = "config/opendaylight-inventory:nodes/node/{nodeId}/table/0/flow/{flowId}",
    url_params = {"flowId" : flowId, "nodeId" : nodeId},
    contentType = "application/json",
    content = buildFlowMod(priority, ethType, ipv4Src, ipv4Dst, flowId, outPort),
    expected_status_code = 200
    )
def interface_configuration_update(
    device_name,
    interface_name,
    description,
    address,
    netmask,
    active='act',
    shutdown=False
):
    '''Update the configuration of the specified interface of the specified device.
    
    The outcome is undefined if the specified device is not connected. 
    '''
    url_suffix = _url_template % (device_name, active, quote_plus(interface_name))
    shutdownField = '\n"shutdown" : "",' if shutdown else ""
    request_content = _request_content_template % (active, netmask, address, shutdownField, interface_name, description)
    odl_http_put(url_suffix, 'application/json', request_content, expected_status_code=200)
def interface_configuration_update(
                                   node_id,
                                   interface_name,
                                   description,
                                   address,
                                   netmask,
                                   active='act',
                                   shutdown=False
                                   ):
    """Update the configuration of the specified interface of the specified device."""
    request_url = _url_interface_configuration.format(**{'config': 'config', 
                                                         'topology-id': 'topology-netconf',
                                                         'node-id': node_id,
                                                         'active': active,
                                                         'interface-name': quote_plus(interface_name),
                                                         })
    request_content = interfaceRequestJSON(active, netmask, address, interface_name, description, shutdown)
    odl_http_put(request_url, 'application/json', request_content, expected_status_code=200)
def interface_toggle(node_id, interface_name, shutdown):
    """Toggle the state of the specified interface of the specified device."""
    url_params = {
        "config": "config",
        "topology-id": "topology-netconf",
        "node-id": node_id,
        "active": "act",
        "interface-name": interface_name,
    }
    ifcfg = interface_configuration(node_id, interface_name)
    if shutdown:
        ifcfg["interface-configuration"][0]["shutdown"] = ""
    else:  # bring back up
        if "shutdown" in ifcfg["interface-configuration"][0]:
            ifcfg["interface-configuration"][0].pop("shutdown")
    request_content = json.dumps(ifcfg)
    odl_http_put(
        _url_interface_configuration, url_params, "application/json", request_content, expected_status_code=200
    )
def interface_configuration_update(device_name,
                                   interface_name,
                                   description=None,
                                   address=None,
                                   netmask=None,
                                   active='act',
                                   shutdown=False):
    '''Update the configuration of the specified interface of the specified device.
    
    The outcome is undefined if the specified device is not connected. 
    '''
    fields = {"interface-name": interface_name}
    if shutdown:
        fields["shutdown"] = ""
    if active:
        fields["active"] = active
    if description:
        fields["description"] = description
    if address or netmask:
        primary = {}
        if address:
            primary["address"] = address
        if netmask:
            primary["netmask"] = netmask
        #TODO test if address is IPv4 or IPv6
        fields["Cisco-IOS-XR-ipv4-io-cfg:ipv4-network"] = {
            "addresses": {
                "primary": primary
            }
        }
    request_content = {"interface-configuration": [fields]}
    url_params = {
        'node-id': device_name,
        'active': active,
        'interface-id': interface_name
    }
    odl_http_put(_configuration_uni_url_template,
                 url_params,
                 'application/json',
                 request_content,
                 expected_status_code=200)
def pushFlow(priority, ethType, ipv4Src, ipv4Dst, flowId, nodeId, outPort):
    return odl_http_put(
        url_suffix=
        "config/opendaylight-inventory:nodes/node/{nodeId}/table/0/flow/{flowId}",
        url_params={
            "flowId": flowId,
            "nodeId": nodeId
        },
        contentType="application/json",
        content=buildFlowMod(priority, ethType, ipv4Src, ipv4Dst, flowId,
                             outPort),
        expected_status_code=200)
Example #12
0
def interface_toggle(node_id, interface_name, shutdown):
    """Toggle the state of the specified interface of the specified device."""
    url_params = {
        'config': 'config',
        'topology-id': 'topology-netconf',
        'node-id': node_id,
        'active': 'act',
        'interface-name': interface_name,
    }
    ifcfg = interface_configuration(node_id, interface_name)
    if shutdown:
        ifcfg['interface-configuration'][0]['shutdown'] = ""
    else:  # bring back up
        if 'shutdown' in ifcfg['interface-configuration'][0]:
            ifcfg['interface-configuration'][0].pop('shutdown')
    request_content = json.dumps(ifcfg)
    odl_http_put(_url_interface_configuration,
                 url_params,
                 'application/json',
                 request_content,
                 expected_status_code=200)
Example #13
0
def interface_configuration_update(node_id,
                                   interface_name,
                                   description,
                                   address,
                                   netmask,
                                   active='act',
                                   shutdown=False):
    """Update the configuration of the specified interface of the specified device."""
    url_params = {
        'config': 'config',
        'topology-id': 'topology-netconf',
        'node-id': node_id,
        'active': active,
        'interface-name': interface_name,
    }
    request_content = interfaceRequestJSON(active, netmask, address,
                                           interface_name, description,
                                           shutdown)
    odl_http_put(_url_interface_configuration,
                 url_params,
                 'application/json',
                 request_content,
                 expected_status_code=200)
Example #14
0
def main():
    if not settings:
        print('Settings must be configured', file=stderr)

    render.print_table(odl_http.coordinates)
    print()

    config = {
        "add-flow": {
            "input": {
                "flow-ref": "1",
                "transaction-uri": "1",
                "flow-table": "1",
                "container-name": "1",
                "cookie_mask": "1",
                "buffer_id": "1",
                "out_port": "1",
                "out_group": "1",
                "flags": "CHECK_OVERLAP",
                "flow-name": "1",
                "installHw": "true",
                "barrier": "true",
                "strict": "true",
                "priority": "1",
                "idle-timeout": "1",
                "hard-timeout": "1",
                "cookie": "1",
                "table_id": "1",
                "node": "1"
            }
        }
    }

    config_str = json.dumps(config)
    try:
        response = odl_http_put(
            url_suffix=
            'http://127.0.0.1:8181/restconf/operations/sal-flow:add-flow',
            url_params={},
            contentType='application/json',
            content=config_str)
        print(response)
    except Exception as e:
        print(e, file=stderr)
Example #15
0
def main():
    if not settings:
        print('Settings must be configured', file=stderr)
    
    render.print_table(odl_http.coordinates)
    print()
    
    config = {
    "add-flow": {
        "input": {
            "flow-ref": "1",
            "transaction-uri": "1",
            "flow-table": "1",
            "container-name": "1",
            "cookie_mask": "1",
            "buffer_id": "1",
            "out_port": "1",
            "out_group": "1",
            "flags": "CHECK_OVERLAP",
            "flow-name": "1",
            "installHw": "true",
            "barrier": "true",
            "strict": "true",
            "priority": "1",
            "idle-timeout": "1",
            "hard-timeout": "1",
            "cookie": "1",
            "table_id": "1",
            "node": "1"
             }
            }
     }
    
    config_str = json.dumps(config)
    try:
        response = odl_http_put(
                      url_suffix='http://127.0.0.1:8181/restconf/operations/sal-flow:add-flow',
                      url_params={},
                      contentType='application/json',
                      content=config_str)
        print(response)
    except Exception as e:
        print(e, file=stderr)