def __init__(self): self.auth = HTTPBasicAuth('admin','admin') # API para adicionar fluxos self.API = 'http://{node}:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:1/table/0/flow/{{id}}' self.master_index = int(getOwner()) self.master = "172.28.1.%s" % self.master_index self.API = self.API.format(node=self.master) self.generator = MacGenerator() self.headers = {'Accept': 'application/json', 'Content-Type': 'application/json'} self.flow = { "flow": [ { "id": "5", "cookie": 38, "instructions": { "instruction": [ { "order": 0, "apply-actions": { "action": [ { "order": 0, "drop-action": { } } ] } } ] }, "hard-timeout": 65000, "match": { "ethernet-match": { "ethernet-type": { "type": 2048 }, "ethernet-source": { "address" : "fake" } }, "ipv4-destination": "10.0.0.38/32" }, "flow-name": "TestFlow-1", "strict": False, "cookie_mask": 4294967295, "priority": 2, "table_id": 0, "idle-timeout": 65000, "installHw": False }]}
def __init__(self,generator): self.auth = HTTPBasicAuth('admin','admin') # API para adicionar fluxos self.API = 'http://{node}:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:1/table/0/flow/{{id}}' self.API = self.API.format(node=getOwner()) self.generator = generator self.headers = {'Accept': 'application/json', 'Content-Type': 'application/json'} self.session = requests.Session()
def getTableFlow(self,size): next_index = ((self.master_index+1)%size)+1 new_master_index = getOwner(next_index) new_master = "172.28.1.%s" % new_master_index print("MASTER: {master}".format(master=new_master)) D_API="http://{node}:8181".format(node=new_master) FLOW_TABLE_REQUEST="/restconf/operational/opendaylight-inventory:nodes/node/openflow:1/table/0/" result = requests.get(D_API+FLOW_TABLE_REQUEST,auth=self.auth,headers=self.headers) print("######### Flow table of Openflow:1 #############") print(result.json())
def emptyNet(n_control=3): switch = partial(OVSSwitch, protocols='OpenFlow13') link = partial(TCLink, bw=100) topo = LinearTopo(k=1, n=2) net = Mininet(controller=RemoteController, switch=switch, link=link, topo=topo, build=False, autoSetMacs=True) controllers = [] for i in range(n_control): posfix = i + 1 ip_address = "172.28.1.%d" % posfix controllers.append( net.addController('c%s' % i, controller=RemoteController, ip=ip_address, port=6633)) net.build() net.start() # Aguarda até que haja estabilidade dos controladores após conexão dos switches time.sleep(5 * n_control) # Cria objeto de comunicação com API REST # flows = Flows() # Envia fluxo para a API # flows.singleFlow() master = getOwner() h1 = net.getNodeByName("h1s1") t = Thread(target=host_send, args=[ h1, ]) t.start() # Tempo necessário para instalação de regras no ONOS time.sleep(10) # print("######### OVS-OFCTL dump before crash ###########") # print(os.popen("ovs-ofctl dump-flows -O openflow13 s1").read()) # print("######### OVS-VSCTL lista controladores before crash #########") # print(os.popen("ovs-vsctl list controller").read()) # Bloqueia conexões com iptables # os.system("iptables -A INPUT -s 172.17.0.5 -j DROP") # os.system("iptables -A OUTPUT -d 172.17.0.5 -j DROP") # Mata o container docker print(os.popen("docker kill --signal=9 odl-%s" % master).read()) t.join() # Tempo maximo para alcancar sincronia time.sleep(10) # print("######### OVS-OFCTL dump after crash ###########") # print(os.popen("ovs-ofctl dump-flows -O openflow13 s1").read()) print("######### OVS-VSCTL lista controladores after crash #########") print(os.popen("ovs-vsctl list controller").read()) # flows.getTableFlow(n_control) # time.sleep(1) # CLI(net) net.stop()