Beispiel #1
0
 def run(self, line):
     if (common.get_console().prompt == common.get_user_name()):
         print("Reloading Bridge")
         common.reset()
         vswitch.ovs_vsctl_del_bridge("br0")
         vswitch.ovs_vsctl_add_bridge("br0")
         for i in range(0, common.get_len_interfaces()):
             vswitch.ovs_vsctl_add_port_to_bridge(
                 "br0", common.get_item_interfaces(i))
     else:
         print(Colors.FAIL + "[ERROR] " + Colors.ENDC + "Bad Command use")
Beispiel #2
0
 def xmlrpc_create_bridge(self, brname):
     """
     Creates an OVS bridge.
     """
     ret = vswitch.ovs_vsctl_add_bridge(brname)
     if ret == 0:
         self.bridges.add(brname)
     return ret
Beispiel #3
0
 def xmlrpc_create_bridge(self, brname):
     """
     Creates an OVS bridge.
     """
     ret = vswitch.ovs_vsctl_add_bridge(brname)
     if ret == 0:
         self.bridges.add(brname)
     return ret
Beispiel #4
0
    def xmlrpc_create_test_bridge(self, bridge, iface):
        """
        This function creates a physical bridge from iface. It moves the
        IP configuration from the physical interface to the bridge.
        """
        ret = vswitch.ovs_vsctl_add_bridge(bridge)
        if ret == 0:
            self.pbridges.add((bridge, iface))
            util.interface_up(bridge)
            (ip_addr, mask) = util.interface_get_ip(iface)
            util.interface_assign_ip(bridge, ip_addr, mask)
            util.move_routes(iface, bridge)
            util.interface_assign_ip(iface, "0.0.0.0", "255.255.255.255")
            ret = vswitch.ovs_vsctl_add_port_to_bridge(bridge, iface)
            if ret == 0:
                self.ports.add(iface)
            else:
                util.interface_assign_ip(iface, ip_addr, mask)
                util.move_routes(bridge, iface)
                vswitch.ovs_vsctl_del_bridge(bridge)

        return ret
Beispiel #5
0
    def xmlrpc_create_test_bridge(self, bridge, iface):
        """
        This function creates a physical bridge from iface. It moves the
        IP configuration from the physical interface to the bridge.
        """
        ret = vswitch.ovs_vsctl_add_bridge(bridge)
        if ret == 0:
            self.pbridges.add((bridge, iface))
            util.interface_up(bridge)
            (ip_addr, mask) = util.interface_get_ip(iface)
            util.interface_assign_ip(bridge, ip_addr, mask)
            util.move_routes(iface, bridge)
            util.interface_assign_ip(iface, "0.0.0.0", "255.255.255.255")
            ret = vswitch.ovs_vsctl_add_port_to_bridge(bridge, iface)
            if ret == 0:
                self.ports.add(iface)
            else:
                util.interface_assign_ip(iface, ip_addr, mask)
                util.move_routes(bridge, iface)
                vswitch.ovs_vsctl_del_bridge(bridge)

        return ret
Beispiel #6
0
import vswitch

#borramos configuracion anterior
vswitch.ovs_vsctl_del_bridge("br0")
#creamos el bridge br0
vswitch.ovs_vsctl_add_bridge("br0")

#anadimos interfaces administrativas
vswitch.ovs_vsctl_admin_port("br0", "vlan10", "10")
vswitch.ovs_vsctl_set_admin("vlan10", "internal")
vswitch.ovs_vsctl_admin_port("br0", "vlan20", "20")
vswitch.ovs_vsctl_set_admin("vlan20", "internal")
vswitch.ifconfig("192.168.0.10/24", "vlan10")
vswitch.ifconfig("192.168.1.10/24", "vlan20")

#anadimos las interfaces al bridge
vswitch.ovs_vsctl_add_port_to_bridge("br0", "eth2")
vswitch.ovs_vsctl_add_port_to_bridge("br0", "eth3")
vswitch.ovs_vsctl_add_port_to_bridge("br0", "eth4")
vswitch.ovs_vsctl_add_port_to_bridge("br0", "eth5")

#metemos los vpcs a vlan 10 y 20
vswitch.ovs_vsctl_set("Port", "eth2", "tag", None, "10")
vswitch.ovs_vsctl_set("Port", "eth3", "tag", None, "10")
vswitch.ovs_vsctl_set("Port", "eth4", "tag", None, "20")
vswitch.ovs_vsctl_add_trunk_port("eth5", "trunks=10,20")
#vswitch.ovs_vsctl_set("Port","eth5","tag",None,"20")
Beispiel #7
0
 def start(self):
     ovs_vsctl_add_bridge(self.name)	
Beispiel #8
0
def main():
    hostname = Hostname("hostname",
                        help="Usage: hostname [name]",
                        dynamic_args=True)
    configureswitch = ConfigureSwitch(
        "configure",
        help="Usage: configure to access to the switch configuration")
    vlan = Vlan("vlan", help="Usage: vlan [vlan id]", dynamic_args=True)
    vlan_name = VlanName("name", help="Usage: name [vlan_name]")
    show = Show("show",
                help="Usage: show [interfaces | vlan ]",
                dynamic_args=True)
    exit = Exit("exit", help="Usage: exit", dynamic_args=True)
    history = History("history", help="Usage: history")
    configure_interface = ConfigureInterface(
        "interface", help="Usage: interface [interface]", dynamic_args=True)
    switchport = Switchport(
        "switchport",
        help=
        "switchport [mode|access|trunk]:\n \tmode: switchport mode [access|trunk]\n \taccess: switchport access vlan [access vlan]\n \ttrunk: switchport trunk allowed vlan [allowed vlan's]",
        dynamic_args=True)
    ipadmininterface = IPAdminInterface(
        "ip",
        help="Usage: ip address [ip] [short|long mask]",
        dynamic_args=True)
    saveload = Save_Load(
        "copy",
        help=
        "Usage: Load Config: copy startup-config running-config || Save: copy running-config startup-config",
        dynamic_args=True)
    no = No("no", help="Usage: no [vlan] [vlan_id]", dynamic_args=True)
    ping = Ping("ping", help="Usage: ping [ip address]")
    shutdown = Shutdown("shutdown", help="Usage: shutdown", dynamic_args=True)
    see = See("see", help="Show in OpenVSwitch")
    reload_ = Reload("reload", help="Reset bridge", dynamic_args=True)
    actualcommand = ActualCommand("?", help="Actual command depends of prompt")
    common.get_console().addChild(configureswitch)
    common.get_console().addChild(hostname)
    common.get_console().addChild(vlan)
    common.get_console().addChild(vlan_name)
    common.get_console().addChild(exit)
    common.get_console().addChild(switchport)
    common.get_console().addChild(show)
    common.get_console().addChild(history)
    common.get_console().addChild(configure_interface)
    common.get_console().addChild(ipadmininterface)
    common.get_console().addChild(no)
    common.get_console().addChild(saveload)
    common.get_console().addChild(ping)
    common.get_console().addChild(see)
    common.get_console().addChild(actualcommand)
    common.get_console().addChild(shutdown)
    common.get_console().addChild(reload_)
    subprocess.call(["/etc/init.d/openvswitch-switch", "start"])
    if (vswitch.ovs_vsctl_is_ovs_bridge("br0") == False):
        vswitch.ovs_vsctl_add_bridge("br0")
        print(Colors.OKGREEN + "[OK] " + Colors.ENDC +
              "Bridge Created with name br0")
        contador = 0
        load_or_not = raw_input("Do you have any configuration saved? (y/n): ")
        if (load_or_not == "y"):
            common.get_console().walk(
                "copy startup-config running-config",
                0,
                run=True,
                full_line="copy startup-config running-config")
        for i in range(0, common.get_len_interfaces()):
            vswitch.ovs_vsctl_add_port_to_bridge("br0",
                                                 common.get_item_interfaces(i))
            vswitch.iplink(common.get_item_interfaces(i), "down")
            contador = contador + 1
            print(Colors.OKGREEN + "[OK] " + Colors.ENDC + "Adding " +
                  str(contador) + " interface to bridge br0")
    common.get_console().loop()
    print(Colors.OKBLUE + "Bye" + Colors.ENDC)