예제 #1
0
		def LastSwitch():
			switchRead = {}
			for dpid in switches:
				switchRead[dpid] = False
				
			for p in monitored_paths: #Walk through all distinct paths and select both last and first switch to calculate throughput and packet loss.
				if switchRead[p.dst] == False:
					switchRead[p.dst] = True
					msg = of.ofp_stats_request(body=of.ofp_flow_stats_request())
					switches[p.dst].connection.send(msg)
				
				if switchRead[p.src] == False:
					switchRead[p.src] = True
					msg = of.ofp_stats_request(body=of.ofp_flow_stats_request())
					switches[p.src].connection.send(msg)
예제 #2
0
		def LastSwitch():
			switchRead = {}
			for dpid in switches:
				switchRead[dpid] = False
				
			for p in monitored_paths: #Walk through all distinct paths and select both last and first switch to calculate throughput and packet loss.
				if switchRead[p[-1]] == False:
					switchRead[p[-1]] = True
					msg = of.ofp_stats_request(body=of.ofp_flow_stats_request())
					switches[p[-1]].connection.send(msg)
				
				if switchRead[p[0]] == False:
					switchRead[p[0]] = True
					msg = of.ofp_stats_request(body=of.ofp_flow_stats_request())
					switches[p[0]].connection.send(msg)
예제 #3
0
def servidorSocketSobrecarga():
	global listaIDS
	global listaIDSold
	global ipBro
	global mensagem
	global pronto
	CAPACIDADE = 50
	listaIDS=[]
	inserirMaquina(listaIDS, 'sdn_firewall_dpi_bro', 6)
	porta = 3000
	socketControlador = socket(AF_INET,SOCK_STREAM)
	socketControlador.bind(('',porta))
	socketControlador.listen(1)
	#print 'O servidor esta funcionando'
	while 1:
		conexao, endereco = socketControlador.accept()
		ipBro = None
		listaIDSold = listaIDS[:]
		mensagem = conexao.recv(1024)
		#print 'Alarme recebido\n'
		if mensagem == "sobrecarga":
			inserirMaquina(listaIDS, 'sdn_firewall_dpi2', 4)
			pronto=False
			while True:
				#print 'peeeera'
				if pronto == True:
					break
		elif mensagem == "descarga":
			removerMaquina(listaIDS, 4)
		conexao.close()
		for switchControlado in core.openflow.connections:
			switchControlado.send(of.ofp_stats_request(body=of.ofp_flow_stats_request()))
	thread.exit()
예제 #4
0
def _timer_func ():
	for connection in core.openflow._connections.values():
		connection.send(of.ofp_stats_request(body=of.ofp_flow_stats_request()))
		# We could even request port stats!
		#connection.send(of.ofp_stats_request(body=of.ofp_port_stats_request()))
		print "Sent " + str(len(core.openflow._connections))+ " flowstats request(s)"
  		log.info("Sent %i flow/port stats request(s)", )
예제 #5
0
def _timer_func():
    for connection in core.openflow._connections.values():
        connection.send(of.ofp_stats_request(body=of.ofp_flow_stats_request()))
# JRF:  Not requesting port stats now
#    connection.send(of.ofp_stats_request(body=of.ofp_port_stats_request()))
    log.debug("Sent %i flow/port stats request(s)",
              len(core.openflow._connections))
예제 #6
0
파일: of_service.py 프로젝트: 09beeihaq/pox
  def _exec_cmd_get_flow_stats (self, event):
    try:
      msg = event.msg
      dpid = strToDPID(msg['dpid'])
      con = core.openflow.getConnection(dpid)
      if con is None:
        raise RuntimeError("No such switch")

      match = event.msg.get('match')
      table_id = event.msg.get('table_id', 0xff)
      out_port = event.msg.get('out_port', of.OFPP_NONE)

      sr = of.ofp_stats_request()
      sr.body = of.ofp_flow_stats_request()
      if match is None:
        match = of.ofp_match()
      else:
        match = dict_to_match(match)
      sr.body.match = match
      sr.body.table_id = table_id
      sr.body.out_port = out_port
      con.send(sr)
      self.reply(event,**{'type':'set_table','xid':sr.xid})

    except:
      #log.exception("Exception in get_flow_stats")
      log.debug("Exception in get_flow_stats - %s:%s",
                sys.exc_info()[0].__name__,
                sys.exc_info()[1])
      self.reply(event,
                 exception="%s: %s" % (sys.exc_info()[0],sys.exc_info()[1]),
                 traceback=traceback.format_exc())
예제 #7
0
    def requestStats(self):
        #Requests udp statistics from the switch that is connected to clients

        self.unblockTried = set()

        for connection in core.openflow.connections:
            connection.send(of.ofp_stats_request(body=of.ofp_flow_stats_request()))
예제 #8
0
파일: statistics.py 프로젝트: krman/thesis
 def _request_stats(self):
     """
     Send OFPT_STATS_REQUEST messages to every known switch.
     """
     for connection in core.openflow._connections.values():
         connection.send(
                 of.ofp_stats_request(body=of.ofp_flow_stats_request()))
예제 #9
0
파일: Monitoring.py 프로젝트: GSap/TestRepo
    def SendFlowStatsReq(self):
        # Send flow stat requests to every switch that has active flows.

        del self.PolSwitches[:] # empty the plist of switches to be polled in order to calculate it again.

        # I must remove old link current values so that calculations are executed correctly when i get responses
        core.current_topology.resetLinkCounters()

        if core.forwarding.ActFlows:
            log.debug("Sending Flow Stat Requests to all switches that have active flows")
            # Here is where i should remove non-active flows
            core.forwarding.removeInactiveFlows()

            # log.debug("Before Sending Flow Stats messages the ActFlow list is:")
            for fl in core.forwarding.ActFlows:
                # print fl.flow_match.s_ip, fl.flow_match.d_ip, fl.used_path, fl.active
                for r in fl.used_path:
                    if (fl.used_path[fl.used_path.index(r)][0]) not in self.PolSwitches:
                        self.PolSwitches.append(fl.used_path[fl.used_path.index(r)][0])
        else:
            log.debug("No active flows at the moment, so not sending any flow stat requests")


        self.pol_counter+=1# increment polling session number

        if self.PolSwitches:
            for con in core.openflow.connections:
                if dpid_to_str(con.dpid) in self.PolSwitches:
                    log.debug("SendingFlowStatsRequest to %s: ", dpid_to_str(con.dpid))
                    msg = of.ofp_stats_request(body=of.ofp_flow_stats_request())
                    con.send(msg)
예제 #10
0
파일: hederapox.py 프로젝트: xkwang/hedera
 def _beginDemandEstimation(self):
     if self.all_switches_up:
         self.demandEstimationLock.acquire()
         # Clear all
         self.flows = []
         self.flowQueryMsg = {}  #set() # Store response to be received
         # Ask for outgoing flow from edge switches to hosts
         for sw_name in self.t.layer_nodes(self.t.LAYER_EDGE):
             connected_hosts = self.t.down_nodes(sw_name)
             sw_dpid = self.t.id_gen(name=sw_name).dpid
             self.flowQueryMsg[sw_dpid] = 0
             for host_name in connected_hosts:
                 sw_port, host_port = self.t.port(sw_name, host_name)
                 msg = of.ofp_stats_request()
                 msg.type = of.OFPST_FLOW
                 msg.body = of.ofp_flow_stats_request()
                 msg.body.out_port = sw_port
                 msg.body.match.nw_proto = ipv4.TCP_PROTOCOL
                 self.switches[sw_dpid].connection.send(msg)
                 # print "request (sw, src_port) = (" + str(sw_dpid) + ", " + str(sw_port) + ")"
                 #self.flowQueryMsg.add((sw_dpid, sw_port))
                 # NOTE: sw_port doesn't match what we get back from openflow.
                 # So, the best we can do is to count it...
                 self.flowQueryMsg[sw_dpid] += 1
         self.demandEstimationLock.release()
     timer = Timer(2.0, self._beginDemandEstimation)
     timer.start()
예제 #11
0
def decider(bool_val, packet):
  global layer1_correct
  global last_packet

  if bool_val:
    last_packet = packet
    print "### Stage 2: Started ###"
    print "Question A: No, Policy does not match actual behaviour"
    print "Searching Question B: 'Does policy match device state?'"
    layer1_correct = False
    # Seatch deeper on device state (Layer 2)
    #start_spanning_tree()
    con_check = check_switch_connectivity()
    
    # Request flow stats (Layer 3 Question D)
    if con_check: # if Yes on question B
        print "### Stage 3: Started ###"
        print "Question B: Yes, Device state matches Policy."
        print "Searching  Question D: 'Does device state match hardware?'"
        for con in core.openflow._connections.values():
            print "Requesting flow table entries from device", con
            con.send(of.ofp_stats_request(body=of.ofp_flow_stats_request()))
    else:
        print "### Stage 3: Started"
        print "Question B: No, Device state doesn't match Policy."
        print "Searching  Question C: 'Does physical view  match Device State?'"
예제 #12
0
파일: Monitoring.py 프로젝트: GSap/TestRepo
    def SendFlowStatsReq(self):
        # Send flow stat requests to the first switch in the path of every active flow.

        del self.PolSwitches[:] # empty the plist of switches to be polled in order to calculate it again.

        if core.forwarding.ActFlows:
            log.debug("Sending Flow Stat Request to the first switch in the path of every active flow.")
            # Here is where i should remove non-active flows
            core.forwarding.removeInactiveFlows()

            # log.debug("Before Sending Flow Stats messages the ActFlow list is:")
            for fl in core.forwarding.ActFlows:
                # print fl.flow_match.s_ip, fl.flow_match.d_ip, fl.used_path, fl.active
                if (fl.used_path[0][0]) not in self.PolSwitches:
                    self.PolSwitches.append(fl.used_path[0][0])
        else:
            log.debug("No active flows at the moment, so not sending any flow stat requests")

        self.pol_counter+=1# increment polling session number

        if self.PolSwitches:
            for con in core.openflow.connections:
                if dpid_to_str(con.dpid) in self.PolSwitches:
                    log.debug("SendingFlowStatsRequest to %s: ", dpid_to_str(con.dpid))
                    msg = of.ofp_stats_request(body=of.ofp_flow_stats_request())
                    con.send(msg)
예제 #13
0
def _handle_ConnectionUp(event):
    if (dpidToStr(event.dpid) == '00-e0-4c-2a-33-4f'):
        nomeswitch = 'Switch UL'
    elif (dpidToStr(event.dpid) == '00-08-54-aa-cb-bc'):
        nomeswitch = 'Switch DL'
    elif (dpidToStr(event.dpid) == '00-06-4f-86-af-ff'):
        nomeswitch = 'Switch HW'
    elif (dpidToStr(event.dpid) == '00-40-a7-0c-01-75'):
        nomeswitch = 'Switch SW'
    else:
        nomeswitch = 'Switch desconhecido'

    log.info("%s conectado.", nomeswitch)
    msg1 = of.ofp_flow_mod()
    msg1.match.in_port = 2
    msg1.priority = 2
    msg1.actions.append(of.ofp_action_output(port=1))
    msg1.hard_timeout = 10
    #msg1.flags |= of.OFPFF_SEND_FLOW_REM
    #event.connection.send(msg1)
    addRegra(event, msg1)

    #msg2 = of.ofp_flow_mod()
    #msg2.match.in_port = 3
    #msg2.priority = 2
    #msg2.actions.append(of.ofp_action_output(port = 2))
    #event.connection.send(msg2)
    event.connection.send(
        of.ofp_stats_request(body=of.ofp_flow_stats_request()))
    log.info("Regras adicionadas.")
예제 #14
0
def _timer_func():

    for connection in core.openflow._connections.values():
        connection.send(of.ofp_stats_request(\
                        body = of.ofp_flow_stats_request()))
        log.info("Sent %i flow stats requests",
                 len(core.openflow._connections))
예제 #15
0
def _timer_func():
    """ handler for timer function that sends the requests to all the
        switches connected to the controller.
    """
    log.debug("start check stat")

    for connection in core.openflow._connections.values():

        # FlowStatsReceived
        connection.send(
            of.ofp_stats_request(body=of.ofp_flow_stats_request(), type=of.ofp_stats_types_rev_map.get("OFPST_FLOW"))
        )

        # AggregateFlowStatsReceived
        connection.send(
            of.ofp_stats_request(
                body=of.ofp_aggregate_stats_request(), type=of.ofp_stats_types_rev_map.get("OFPST_AGGREGATE")
            )
        )

        # TableStatsReceived
        # I don't know which methode to call (it's not of.ofp_flow_stats())
        # connection.send(of.ofp_stats_request(body=of.ofp_table_stats()))

        # PortStatsReceived
        connection.send(
            of.ofp_stats_request(
                body=of.ofp_port_stats_request(port_no=of.OFPP_NONE), type=of.ofp_stats_types_rev_map.get("OFPST_PORT")
            )
        )

        # QueueStatsReceived
        body = of.ofp_queue_stats_request(port_no=of.OFPP_NONE, queue_id=of.OFPQ_ALL)
        connection.send(of.ofp_stats_request(body=body, type=of.ofp_stats_types_rev_map.get("OFPST_QUEUE")))
예제 #16
0
        def RoundRobin():
            pathRead = {}
            for p in monitored_paths:
                pathRead[p] = False

            for p in monitored_paths:  #Walk through all distinct paths, not even flows
                if pathRead[p] != True:

                    if p not in pathIterator or pathIterator[
                            p] == p.src:  # Round Robin switch selection
                        pathIterator[p] = p.dst
                    else:
                        pathIterator[p] = p.prev[pathIterator[p]]

                    curSwitch = pathIterator[p]

                    #log.debug("Sending message to switch %s", util.dpid_to_str(curSwitch))
                    msg = of.ofp_stats_request(
                        body=of.ofp_flow_stats_request())
                    switches[curSwitch].connection.send(msg)
                    msg2 = of.ofp_stats_request(
                        body=of.ofp_port_stats_request())
                    switches[curSwitch].connection.send(msg2)
                    for pPrime in monitored_pathsBySwitch[
                            curSwitch]:  #Circumvent polling multiple switches for paths from whom the stats have already been requested
                        pathRead[pPrime] = True
예제 #17
0
	def handle_congestion_notification(self, dpid):
		""" Upon reception of a congestion notification, requests for flow stats in the congestioned switch """
		dpid = dpid[:len(dpid)-1]
                dpid = dpid[len(dpid)-12:]
                #print 'Received dpid: ' + str(dpid)

		# We leave the 10% to handle new flows, during congestion.

		# Request flow stats from switch
		#print "dpid parameter: " + str(dpid)
		switch=dict.fromkeys(['dpid', 'flow_stats', 'wait_flag', 'drop_policy', 'bw_policy'])
		switch['drop_policy'] = 'Random'
		switch['bw_policy'] = 'Penalty'
		switch['dpid'] = dpid		
		switch['wait_flag'] = 0
		switch['flow_stats'] = []
		switch_states.append(switch)

		for connection in self.myconnections:
			connection_dpid = connection.dpid
			#print "Connection dpid: " + str(connection_dpid)
			dpid_str = dpidToStr(connection_dpid)
			dpid_str = dpid_str.replace("-", "")
			#print 'Real dpid_str: ' + dpid_str
			if dpid == dpid_str:
				connection.send(of.ofp_stats_request(body=of.ofp_flow_stats_request()))
				print 'Flow stats requets sent to: ' + str(connection)
예제 #18
0
    def _exec_cmd_get_flow_stats(self, event):
        try:
            msg = event.msg
            dpid = strToDPID(msg['dpid'])
            con = core.openflow.getConnection(dpid)
            if con is None:
                raise RuntimeError("No such switch")

            match = event.msg.get('match')
            table_id = event.msg.get('table_id', 0xff)
            out_port = event.msg.get('out_port', of.OFPP_NONE)

            sr = of.ofp_stats_request()
            sr.body = of.ofp_flow_stats_request()
            if match is None:
                match = of.ofp_match()
            else:
                match = dict_to_match(match)
            sr.body.match = match
            sr.body.table_id = table_id
            sr.body.out_port = out_port
            con.send(sr)
            self.reply(event, **{'type': 'set_table', 'xid': sr.xid})

        except:
            #log.exception("Exception in get_flow_stats")
            log.debug("Exception in get_flow_stats - %s:%s",
                      sys.exc_info()[0].__name__,
                      sys.exc_info()[1])
            self.reply(event,
                       exception="%s: %s" %
                       (sys.exc_info()[0], sys.exc_info()[1]),
                       traceback=traceback.format_exc())
예제 #19
0
	def request_stats(self):
		# Get consumption of each node in the topology
		for i in range(len(info_manager.nodes)):
			self.count_flow_stats_straight += 1
			self.count_port_stats_straight += 1


		for h in info_manager.hosts:
			border_node = info_manager.get_node(h.dpid)
			try:
				core.openflow.getConnection(border_node.id).send(of.ofp_stats_request(body=of.ofp_flow_stats_request()))
				self.count_flow_stats_adaptive += 1
			except:
				continue

		nodes_list = self.G.nodes()
		aux = 0
		for node in nodes_list:
			aux += 1
			connection = core.openflow.getConnection(node)
			if connection:
				connection.send(of.ofp_stats_request(body=of.ofp_port_stats_request()))
				self.count_port_stats_adaptive += 1

		if aux == 0:
			self.count_port_stats_adaptive = 0

		update_monitoring_stats(self.count_flow_stats_straight, self.count_flow_stats_adaptive, self.count_port_stats_straight, self.count_port_stats_adaptive)
		info_manager.update_network_consumption()
예제 #20
0
    def flow_stat_thread(self):

        while True:

            # Send flow stat to switch
            self._of_send(of.ofp_stats_request(body=of.ofp_flow_stats_request()))
            
            # Save timing events to file.
            with open(TIMING_EVENT_FILE, 'a') as timing_f:
                for (event_name, queue) in [('pkt_in', self.pkt_in_queue), 
                                            ('flow_mod', self.flow_mod_queue)]:
                    while not queue.empty():
                        try:
                            (start_time, packet) = queue.get()
                        except Queue.Empty():
                            break
                        match = of.ofp_match.from_packet(packet)
                        print >> timing_f, '%.8f,%s,%s,%s' % (start_time,
                                                              event_name,
                                                              match.tp_src,
                                                              match.tp_dst)
            
            sleep_time = 0
            while True:
                time.sleep(0.5)
                sleep_time += 0.5
                with self.lock:
                    if sleep_time >= self.flow_stat_interval:
                        break
예제 #21
0
		def dropping (duration=None):
			msg.priority=65535
			msg.actions.append(of.ofp_action_vlan_vid(vlan_vid = 831)) 		# modify the vlan id from the 830 to 831 
			print "dropping packets from ", IP_attack 			
			for connection in self.myconnections:
				connection.send(msg)  													#send the msg to the switch
				connection.send(of.ofp_stats_request(body=of.ofp_flow_stats_request())) #getting the flux stats
				print "MSG sent"
예제 #22
0
def _timer_func():
    for connection in core.openflow._connections.values():
        connection.send(of.ofp_stats_request(body=of.ofp_flow_stats_request()))
        # We could even request port stats!
        #connection.send(of.ofp_stats_request(body=of.ofp_port_stats_request()))
        print "Sent " + str(len(
            core.openflow._connections)) + " flowstats request(s)"
        log.info("Sent %i flow/port stats request(s)", )
예제 #23
0
파일: Statistics.py 프로젝트: hfskappel/ext
def _on_timer():

    for n in nodes:
        #Sends out requests to the network nodes
        core.openflow.getConnection(n.connection.dpid).send(of.ofp_features_request())
        n.connection.send(of.ofp_stats_request(body=of.ofp_port_stats_request()))
        n.connection.send(of.ofp_stats_request(body=of.ofp_aggregate_stats_request()))
        n.connection.send(of.ofp_stats_request(body=of.ofp_flow_stats_request()))
예제 #24
0
def _request_stats():
    log.debug('Number of connections: {}'.format(len(
        core.openflow.connections)))
    log.info('Sending stats requests')
    for connection in core.openflow.connections:
        log.debug("Sending stats request")
        connection.send(of.ofp_stats_request(body=of.ofp_flow_stats_request()))
        connection.send(of.ofp_stats_request(body=of.ofp_port_stats_request()))
예제 #25
0
 def flow_stats_request(self,switch):
     sr = of.ofp_stats_request()
     sr.body = of.ofp_flow_stats_request()
     match = of.ofp_match()
     sr.body.match = match
     sr.body.table_id = 0xff
     sr.body.out_port = of.OFPP_NONE
     self.switches[switch]['connection'].send(sr) 
예제 #26
0
    def requestStats(self):
        "Send all switches a flow statistics request"
        self.flowstats = []
        for connection in core.openflow._connections.values():
            connection.send(
                of.ofp_stats_request(body=of.ofp_flow_stats_request()))

        return True
예제 #27
0
 def flow_stats_request(self, switch):
     sr = of.ofp_stats_request()
     sr.body = of.ofp_flow_stats_request()
     match = of.ofp_match()
     sr.body.match = match
     sr.body.table_id = 0xff
     sr.body.out_port = of.OFPP_NONE
     self.switches[switch]['connection'].send(sr)
예제 #28
0
  def _timer_func (self):
    for connection in core.openflow._connections.values():
      
      print "connection is" 
      print connection
      #if openflowconnection[1]==2:
      connection.send(of.ofp_stats_request(body=of.ofp_flow_stats_request()))
	  # connection.send(of.ofp_stats_request(body=of.ofp_port_stats_request()))
      log.debug("Sent %i flow/port stats request(s)", len(core.openflow._connections))
예제 #29
0
 def _send_ofp_stats_request(self):
     for connection in core.openflow._connections.values():
         connection.send(
             of.ofp_stats_request(body=of.ofp_flow_stats_request()))
         connection.send(
             of.ofp_stats_request(body=of.ofp_port_stats_request()))
     log.debug("Sent %i flow/port stats request(s)",
               len(core.openflow._connections))
     core.flow_stats._raise_StatsEvent()  #invoke event
def send_stats_requests():
  """
  Send stats request to the connecting switch
  """
  for connection in core.openflow._connections.values():
    connection.send(of.ofp_stats_request(body=of.ofp_flow_stats_request()))
    connection.send(of.ofp_stats_request(body=of.ofp_port_stats_request()))

  log.debug("Sent %i flow/port stats request(s)", len(core.openflow._connections))
예제 #31
0
def _timer_func():

    for connection in core.openflow._connections.values():

        dpid_str = dpidToStr(connection.dpid)

        # 给每个connection的sw发送request 可以加if判断发送哪个
        connection.send(of.ofp_stats_request(body=of.ofp_flow_stats_request()))
        connection.send(of.ofp_stats_request(body=of.ofp_port_stats_request()))
예제 #32
0
def timer_func():
    for connection in core.openflow._connections.values():
        connection.send(of.ofp_stats_request(body=of.ofp_flow_stats_request()))
        connection.send(
            of.ofp_stats_request(body=of.ofp_aggregate_stats_request())
        )  # ???????????????not supported in POX yet
        connection.send(of.ofp_stats_request(body=of.ofp_port_stats_request()))
    log.debug("Sent %i flow/port stats request(s)",
              len(core.openflow._connections))
예제 #33
0
def _timer_func ():
  for connection in core.openflow._connections.values():
    
    #log.debug("!!!!!!" + dpidToStr(connection.dpid))
    if(dpidToStr(connection.dpid) == "00-00-00-00-00-05"):
      connection.send(of.ofp_stats_request(body=of.ofp_flow_stats_request()))
      connection.send(of.ofp_stats_request(body=of.ofp_port_stats_request()))

    log.debug("Sent %i flow/port stats request(s)", len(core.openflow._connections))
예제 #34
0
    def _handle_PacketIn(self, event):
        """
    Handle packet in messages from the switch to implement above algorithm.
    """
        packet = event.parsed
        print "Rxed packet: ", packet
        self.handle_IP_packet(packet)

        for con in core.openflow.connections:
            con.send(of.ofp_stats_request(body=of.ofp_flow_stats_request()))
예제 #35
0
파일: poxmgr.py 프로젝트: croft/ravel
    def requestStats(self):
        "Send all switches a flow statistics request"
        self.flowstats = []
        for connection in core.openflow._connections.values():
            connection.send(of.ofp_stats_request(body=of.ofp_flow_stats_request()))

        self.log.debug("ravel: sent {0} flow stats requests".format(
            len(core.openflow._connections)))

        return True
예제 #36
0
 def _handle_PacketIn (self, event):
   """
   Handle packet in messages from the switch to implement above algorithm.
   """
   packet = event.parsed
   print "Rxed packet: ", packet
   self.handle_IP_packet(packet)
   
   for con in core.openflow.connections:
     con.send(of.ofp_stats_request(body=of.ofp_flow_stats_request()))
예제 #37
0
def send_stats_requests():
    """
  Send stats request to the connecting switch
  """
    for connection in core.openflow._connections.values():
        connection.send(of.ofp_stats_request(body=of.ofp_flow_stats_request()))
        connection.send(of.ofp_stats_request(body=of.ofp_port_stats_request()))

    log.debug("Sent %i flow/port stats request(s)",
              len(core.openflow._connections))
예제 #38
0
    def request_stats_loop():
        next_time = math.floor(time.time()) + 0.5
        while True:
            for conn in core.openflow.connections:
                conn.send(
                    of.ofp_stats_request(body=of.ofp_flow_stats_request()))

            while (time.time() >= next_time):
                next_time += stat_interval_seconds
            time.sleep(next_time - time.time())
예제 #39
0
def _timer_func():
    for connection in core.openflow._connections.values():
        global n1
        #print 'n1a=',n1
        connection.send(of.ofp_stats_request(body=of.ofp_flow_stats_request()))
        global n0
        n0 = t.time()
        #connection.send(of.ofp_stats_request(body=of.ofp_port_stats_request()))
    log.debug("Sent %i flow/port stats request(s)",
              len(core.openflow._connections))
예제 #40
0
  def __init__ (self, connection):
    self.connection = connection

    # My table
    self.macToPort = {}

    # We want to hear PacketIn messages, so we listen to the connection
    connection.addListeners(self)
    print "stat message is sent to sw_dpid: ", dpid_to_str(self.connection.dpid)
    self.connection.send(of.ofp_stats_request(body=of.ofp_flow_stats_request()))
예제 #41
0
def start_migration():
    print "Start migration..."

    # bring down the interfaces at ovs-1
    print "bring down the interfaces in ovs-1"
    remote_cmd.ssh_run_cmd(ovs1_IP, "sudo sh interface-down.sh")

    for connection in core.openflow._connections.values():
        if connection.dpid == oldswitch_dpid:
            connection.send(of.ofp_stats_request(body=of.ofp_flow_stats_request()))
            log.debug("Sent %i flow/port stats request(s)", len(core.openflow._connections))
예제 #42
0
    def requestStats(self):
        "Send all switches a flow statistics request"
        self.flowstats = []
        for connection in core.openflow._connections.values():
            connection.send(
                of.ofp_stats_request(body=of.ofp_flow_stats_request()))

        self.log.debug("ravel: sent {0} flow stats requests".format(
            len(core.openflow._connections)))

        return True
예제 #43
0
		def honeypot():
			print "Honeypot"	
			msg.actions.append(of.ofp_action_dl_addr.set_dst(mac_honey)) 	# honeypot MAC address
			msg.actions.append(of.ofp_action_vlan_vid(vlan_vid = 831)) 		# modify the vlan id from the 830 to 831 
			msg.actions.append(of.ofp_action_nw_addr.set_dst(ip_honeypot))  # action to send the flux to the honey_pot
			msg.actions.append(of.ofp_action_output(port = 6)) 			# which port the honeypot is connected 
																		# see how i can get this port by python
			for connection in self.myconnections:
				connection.send(msg)  													#send the msg to the switch
				connection.send(of.ofp_stats_request(body=of.ofp_flow_stats_request())) #getting the flux stats
				print "MSG sent"
예제 #44
0
    def enable_flow_stats_retrieval(self, interval_secs):
        """
		Starts a timer that periodically requests the switch to send flow statistics.
		The reply will be received through a FlowStatsReceived event.
		"""

        self._stats_req_timer = recoco.Timer(
            interval_secs,
            lambda: self._connection.send(
                of.ofp_stats_request(body=of.ofp_flow_stats_request())),
            recurring=True)
예제 #45
0
파일: if_switch.py 프로젝트: thwindbell/pox
  def flow_stats_polling (self):
    """
    Send flow_stats_request every 1sec.
    """

    msg = of.ofp_stats_request(body = of.ofp_flow_stats_request())
    self.connection.send(msg)
    
    # Start next thread after 1sec.
    t = threading.Timer(1, self.flow_stats_polling)
    t.start()
예제 #46
0
파일: flow_tracker.py 프로젝트: doc-vu/sdmc
 def launch_stats_query(self):
     """Sends an OpenFlow FlowStatsRequest and PortStatsRequest to the switch associated with this object."""
     if self.is_connected:
         self.connection.send(
             of.ofp_stats_request(body=of.ofp_flow_stats_request()))
         self._last_flow_stats_query_send_time = time.time()
         self.connection.send(
             of.ofp_stats_request(body=of.ofp_port_stats_request()))
         self._last_port_stats_query_send_time = time.time()
         log.debug('Sent flow and port stats requests to switch: ' +
                   dpid_to_str(self.dpid))
예제 #47
0
파일: webservice.py 프로젝트: yotamhc/pox
 def _init(self, match=None, table_id=0xff, out_port=of.OFPP_NONE):
     sr = of.ofp_stats_request()
     sr.body = of.ofp_flow_stats_request()
     if match is None:
         match = of.ofp_match()
     else:
         match = dict_to_match(match)
     sr.body.match = match
     sr.body.table_id = table_id
     sr.body.out_port = out_port
     self._con.send(sr)
     self.xid = sr.xid
예제 #48
0
    def __init__(self, connection):
        self.connection = connection

        # My table
        self.macToPort = {}

        # We want to hear PacketIn messages, so we listen to the connection
        connection.addListeners(self)
        print "stat message is sent to sw_dpid: ", dpid_to_str(
            self.connection.dpid)
        self.connection.send(
            of.ofp_stats_request(body=of.ofp_flow_stats_request()))
예제 #49
0
 def flow_stats_request(self,switch):
     sr = of.ofp_stats_request()
     sr.body = of.ofp_flow_stats_request()
     match = of.ofp_match()
     sr.body.match = match
     sr.body.table_id = 0xff
     sr.body.out_port = of.OFPP_NONE
     try:
         self.switches[switch]['connection'].send(sr)
     except KeyError, e:
         print ( ("ERROR:flow_stats_request: No connection to switch %d" +
                  " available") % switch )
예제 #50
0
파일: pox_client.py 프로젝트: Ali00/pyretic
 def flow_stats_request(self,switch):
     sr = of.ofp_stats_request()
     sr.body = of.ofp_flow_stats_request()
     match = of.ofp_match()
     sr.body.match = match
     sr.body.table_id = 0xff
     sr.body.out_port = of.OFPP_NONE
     try:
         self.switches[switch]['connection'].send(sr)
     except KeyError, e:
         print ( ("ERROR:flow_stats_request: No connection to switch %d" +
                  " available") % switch )
예제 #51
0
파일: webservice.py 프로젝트: 09beeihaq/pox
 def _init (self, match=None, table_id=0xff, out_port=of.OFPP_NONE):
   sr = of.ofp_stats_request()
   sr.body = of.ofp_flow_stats_request()
   if match is None:
     match = of.ofp_match()
   else:
     match = dict_to_match(match)
   sr.body.match = match
   sr.body.table_id = table_id
   sr.body.out_port = out_port
   self._con.send(sr)
   self.xid = sr.xid
예제 #52
0
  def _handle_timer (self, dpid):
    sw = self.switches.get(dpid)
    if sw is None:
      return

    # send stat request
    body = of.ofp_flow_stats_request()
    ## DAMN! stats can't be requested based on priority.
    #body.priority = of.OFP_DEFAULT_PRIORITY + 1
    msg = of.ofp_stats_request(body=body)
    core.openflow.sendToDPID(dpid, msg.pack())

    core.callDelayed(self.poll_period, self._handle_timer, dpid)
예제 #53
0
def timer_function ():
	"""
	Request Flow and Port Stats
	"""

	for connection in core.openflow._connections.values():
		connection.send(of.ofp_stats_request(body=of.ofp_flow_stats_request()))
		connection.send(of.ofp_stats_request(body=of.ofp_port_stats_request()))

	global timer_now
	timer_now = datetime.datetime.now()
	
	log.debug("Sent %i flow/port stats requests", len(core.openflow._connections))
예제 #54
0
def _handle_timer(message):
		print 
		print message
		connections = core.openflow._connections
		print 'connected switch:',
		for connection in connections:
			print connection,
			# print 'connection:',connection.dpid,connection.ports #to see what connection consists of
			connection.send(of.ofp_stats_request(body = of.ofp_flow_stats_request()))
			connection.send(of.ofp_stats_request(body = of.ofp_port_stats_request()))
			#delet all flows
			connection.send(of.ofp_flow_mod(match = of.ofp_match(),command = of.OFPFC_DELETE))
		print '\n'
예제 #55
0
파일: broflow.py 프로젝트: tinchoa/broflow
		def honeypot():
			print "Honeypot"	
			msg.actions.append(of.ofp_action_dl_addr.set_dst(mac_honey)) 	# honeypot MAC address
			msg.actions.append(of.ofp_action_vlan_vid(vlan_vid = 831)) 		# modify the vlan id from the 830 to 831 
			msg.actions.append(of.ofp_action_nw_addr.set_dst(ip_honeypot))  # action to send the flux to the honey_pot
			msg.actions.append(of.ofp_action_output(port = 6)) 			# which port the honeypot is connected 
			ts = time.time()
			st = datetime.datetime.fromtimestamp(ts).strftime('%H:%M:%S %d-%m-%Y')		
			outputLog.write("Flow Deviated "+ IP_attack +"-->" + IP_dst +' '+ str(st) +'\n')
																		# see how i can get this port by python
			for connection in self.myconnections:
				connection.send(msg)  													#send the msg to the switch
				connection.send(of.ofp_stats_request(body=of.ofp_flow_stats_request())) #getting the flux stats
				print "MSG sent to switchs"
예제 #56
0
    def start_migration(self):
        log.info("start copying flow tables...")

        for connection in core.openflow._connections.values():
            if connection.dpid == ovs1_dpid or connection.dpid == ovs2_dpid or connection.dpid == ovs3_dpid:
                connection.send(of.ofp_stats_request(body=of.ofp_flow_stats_request()))
                log.debug("Sent %i flow/port stats request(s)", len(core.openflow._connections))

                # send barrier message to ensure all flows has been installed
                connection.send(of.ofp_barrier_request(xid=copy_barrier_id))
                connection.addListenerByName("BarrierIn", _handle_flow_ready)

                global barrier_count
                barrier_count += 1
예제 #57
0
	def handle_congestion_notification(self, connections, dpid):
		""" Upon reception of a congestion notification, requests for flow stats in the congestioned switch """
		dpid = dpid[:len(dpid)-1]
                dpid = dpid[len(dpid)-12:]

		switch=dict.fromkeys(['dpid', 'flow_stats', 'drop_policy', 'bw_policy'])
		switch['drop_policy'] = 'Random'
		switch['bw_policy'] = 'Penalty'
		switch['dpid'] = dpid		
		switch['flow_stats'] = []
		switch_states.append(switch)
		Timer(flow_update_time, self.update_flow_stats, recurring = True, args=[dpid, connections])
		msg = of.ofp_stats_request(body=of.ofp_flow_stats_request())
		print 'Flow stats requets sent to: ' + str(connections)		
		self.send_command_to_switch(dpid, connections, msg)