crea una topologia de red que tenga los siguientes aspectos: 1 controlador ryu 2 switches ovs conectados entre si y conectados al controlador 4 host para el s1 y 8 para el s2 3 Vlans, Vlan10 valn20 y vlan30 vlan 20 y 30 estaran en el s2 y vlan 10 en s1 ips para vlan 10 asigan a los host desde el rango 192.168.0.1 - 192.168.0.62/26 vlan 20 asignas 192.168.0.65 - 192.168.0.126 vlan 30 asignas del rango 192.168.0.129 - 192.168.0.190
Aquí te muestro una posible topología de red en Python utilizando la biblioteca `networkx` para representar la red y `matplotlib` para visualizarla. ```python import networkx as nx import matplotlib.pyplot as plt # Creamos un grafo vacío G = nx.Graph() # Agregamos los switches y el controlador G.add_node("S1", type="switch") G.add_node("S2", type="switch") G.add_node("Controller", type="controller") # Agregamos los hosts for i in range(4): G.add_node(f"H{i+1}_S1", type="host") G.add_node(f"H{i+5}_S1", type="host") for i in range(8): G.add_node(f"H{i+1}_S2", type="host") G.add_node(f"H{i+9}_S2", type="host") # Agregamos las conexiones entre los switches y el controlador G.add_edge("S1", "Controller") G.add_edge("S2", "Controller") G.add_edge("S1", "S2") # Agregamos las conexiones entre los hosts y sus respectivos switches for i in range(4): G.add_edge(f"H{i+1}_S1", "S1") G.add_edge(f"H{i+5}_S1", "S1") for i in range(8): G.add_edge(f"H{i+1}_S2", "S2") G.add_edge(f"H{i+9}_S2", "S2") # Agregamos las VLANs G.add_node("VLAN10", type="vlan") G.add_node("VLAN20", type="vlan") G.add_node("VLAN30", type="vlan") # Asignamos los hosts a sus respectivas VLANs for i in range(4): G.add_edge(f"H{i+1}_S1", "VLAN10") G.add_edge(f"H{i+5}_S1", "VLAN10") for i in range(8): G.add_edge(f"H{i+1}_S2", "VLAN20") G.add_edge(f"H{i+9}_S2", "VLAN20") for i in range(8): G.add_edge(f"H{i+1}_S2", "VLAN30") G.add_edge(f"H{i+9}_S2", "VLAN30") # Asignamos las IPs a los hosts for i in range(4): G.nodes[f"H{i+1}_S1"]["ip"] = f"192.168.0.{i+1}" G.nodes[f"H{i+5}_S1"]["ip"] = f"192.168.0.{i+65}" for i in range(8): G.nodes[f"H{i+1}_S2"]["ip"] = f"192.168.0.{i+129}" G.nodes[f"H{i+9}_S2"]["ip"] = f"192.168.0.{i+189}" # Visualizamos la red pos = nx.spring_layout(G) nx.draw_networkx_nodes(G, pos, node_size=5000, node_color="lightblue") nx.draw_networkx_labels(G, pos, font_size=10) nx.draw_networkx_edges(G, pos, width=2, edge_color="gray") nx.draw_networkx_nodes(G, pos, nodelist=[n for n in G.nodes if G.nodes[n]["type"] == "vlan"], node_size=5000, node_color="lightgreen") nx.draw_networkx_nodes(G, pos, nodelist=[n for n in G.nodes if G.nodes[n]["type"] == "controller"], node_size=5000, node_color="lightcoral") nx.draw_networkx_nodes(G, pos, nodelist=[n for n in G.nodes if G.nodes[n]["type"] == "switch"], node_size=5000, node_color="lightgray") nx.draw_networkx_nodes(G, pos, nodelist=[n for n in G.nodes if G.nodes[n]["type"] == "host"], node_size=5000, node_color="lightyellow") plt.show() ``` Este código crea una red con los elementos solicitados y asigna las IPs a los hosts según las VLANs. La red se visualiza con diferentes colores para los diferentes tipos de nodos. Recuerda que debes tener instaladas las bibliotecas `networkx` y `matplotlib` para ejecutar este código. Puedes instalarlas con pip: ```bash pip install networkx matplotlib ```