Exemple #1
0
def launch(dpid, __INSTANCE__=None, **kw):
    if not core.hasComponent("OVSRIPRouters"):
        core.registerNew(OVSRIPRouters)

    if not core.hasComponent("NX"):
        import pox.openflow.nicira
        pox.openflow.nicira.launch(convert_packet_in=True)

    try:
        dpid = long(dpid)
    except:
        dpid = util.str_to_dpid(dpid)

    r = OVSRIPRouter(dpid=dpid)
    core.OVSRIPRouters.add(r)

    # Directly attached networks
    for iface, routes in kw.items():
        # Try to parse iface as a port number; else a name
        try:
            iface = int(iface)
        except:
            pass
        routes = routes.split(',')
        for route in routes:
            ip, prefix_size = IPAddr.parse_cidr(route, allow_host=True)
            prefix = ip.get_network(prefix_size)
            r.add_direct_network(iface, ip=ip, prefix=prefix)
Exemple #2
0
def static(dpid, __INSTANCE__=None, **kw):
    try:
        dpid = long(dpid)
    except:
        dpid = util.str_to_dpid(dpid)

    r = core.OVSRIPRouters.get(dpid=dpid)
    for prefix, rest in kw.items():
        prefix = IPAddr.parse_cidr(prefix)
        rest = rest.split(",")
        next_hop = IPAddr(rest[0])
        rest = rest[1:]
        attrs = {}
        for attr in rest:
            k, v = attr.split(":", 1)
            f = {"metric": int}[k]  # Fail for other
            attrs[k] = f(v)
        r.add_static_route(prefix=prefix, next_hop=next_hop, **attrs)