def ipdstrw_and_forward(self, dpid, inport, packet, buf, bufid):
        logger.info('IPDBF:[' + str(buf) + ']{' + str(packet) + '}\n')
        buf[30] = 10
        buf[31] = 0
        buf[32] = 0
        buf[33] = 3
        packet.next.dstip = ipstr_to_int('10.0.0.3')
        IPHeaderChecksum = (packet.next).checksum()
        buf[24] = IPHeaderChecksum >> 8
        buf[25] = IPHeaderChecksum & 0xFF
        logger.info('Checksum: ' + str(IPHeaderChecksum) + '\n')
        logger.info('IPDAF:[' + str(buf) + ']{' + str(packet) + '}\n')

        # push down flow entry
        flow = {}
        flow[DL_TYPE] = 0x0800
        flow[NW_DST] = ipstr_to_int('10.0.0.5')
        actions = [
                  [openflow.OFPAT_SET_NW_DST, ipstr_to_int('10.0.0.3')],
                  [openflow.OFPAT_OUTPUT, [0, 1]]
                  ]
        CACHE_TIMEOUT = 100
        self.install_datapath_flow(dpid, flow, CACHE_TIMEOUT,
                                   openflow.OFP_FLOW_PERMANENT, actions,
                                   None, openflow.OFP_DEFAULT_PRIORITY,
                                   inport, None)
Beispiel #2
0
def get_forwarding_srcrule(srcIP, srcMAC, dstMAC, dstIP, outport):
    flow = {}
    flow[DL_TYPE] = 0x0800
    flow[NW_DST] = ipstr_to_int(srcIP)
    defaultActions = [
	      [openflow.OFPAT_OUTPUT, [0, outport]]
	      ]
    rewriteActions = [
              [openflow.OFPAT_SET_DL_SRC, dstMAC],
              [openflow.OFPAT_SET_NW_SRC, ipstr_to_int(dstIP)],
	      [openflow.OFPAT_SET_DL_DST, octstr_to_array(srcMAC)],
              [openflow.OFPAT_OUTPUT, [0, outport]]
              ]
    return (flow, defaultActions, rewriteActions)
Beispiel #3
0
    def packet_in_callback(self, dpid, inport, reason, len, bufid, packet):
        if packet.type == Globals.ARP_TYPE:
	    # ARP Response from replicas for our ARP Requests
            if packet.dst == octstr_to_array(Globals.VMAC):
                self.foundMac(dpid, mac_to_str(packet.src), ip_to_str(packet.next.protosrc), inport)
	    # Request for VIP, respond with ARP Response
            elif packet.next.protodst == ipstr_to_int(Globals.VIP):
		Globals.STATSLOG.write(mac_to_str(dpid) + ' received ' + ip_to_str(packet.next.protosrc) + '\n')
                srcIP = ip_to_str(packet.next.protosrc)
		# Install Rewrite Rules
                (flow, defaultActions, rewriteActions) = IPs.get_forwarding_srcrule(srcIP, mac_to_str(packet.src), Globals.VMAC, Globals.VIP, inport)
                Multipath.install_microflow_flow(flow, openflow.OFP_FLOW_PERMANENT, openflow.OFP_FLOW_PERMANENT, defaultActions, None, openflow.OFP_DEFAULT_PRIORITY + 20, 0, None, dpid, inport, rewriteActions)
		# Response
                arpResponse = Arps.create_virtual_arp_response(packet, octstr_to_array(Globals.VMAC), ipstr_to_int(Globals.VIP))
                Multipath.send(dpid, None, arpResponse, [[openflow.OFPAT_OUTPUT, [0, inport]]], openflow.OFPP_CONTROLLER)
                ip = ip_to_str(packet.next.protosrc)
                for i, switchJ in enumerate(Globals.SWITCHES):
                    if switchJ['mac'] == dpid:
                        found = False
			for i, client in enumerate(switchJ['clients']):
			    if client['ip'] == ip:
 				found = True
			if not found:
   			    Globals.STATSLOG.write(mac_to_str(dpid) + ' found ' + ip + '\n')
                            switchJ['clients'].append({'port': inport, 'ip': ip, 'oldCount': 0L, 'newCount': 0L, 'avg': 0L})
            elif packet.src != octstr_to_array(Globals.VMAC):
		Globals.STATSLOG.write(mac_to_str(dpid) + ' received REQ ' + ip_to_str(packet.next.protosrc) + '\n')
                arpResponse = Arps.create_arp_response(packet)
                Multipath.send(dpid, None, arpResponse, [[openflow.OFPAT_OUTPUT, [0, inport]]], openflow.OFPP_CONTROLLER)
	elif packet.type == Globals.IP_TYPE:
            if reason == openflow.OFPR_ACTION:
                IPTransition.handleControllerAction(packet)
Beispiel #4
0
def get_forwarding_dstrule(srcIP, srcWild, gateIP, dstMAC, dstIP, outport):
    flow = {}
    flow[DL_TYPE] = 0x0800
    flow[NW_SRC] = srcIP
    flow[NW_SRC_N_WILD] = srcWild
    flow[NW_DST] = ipstr_to_int(gateIP)
    defaultActions = [
              [openflow.OFPAT_OUTPUT, [0, outport]]
              ]
    rewriteActions = [
              [openflow.OFPAT_SET_DL_DST, dstMAC],
              [openflow.OFPAT_SET_NW_DST, ipstr_to_int(dstIP)],
              [openflow.OFPAT_OUTPUT, [0, outport]]
              ]

    return (flow, defaultActions, rewriteActions)
Beispiel #5
0
    def arpRequestReplicas(self):
	for i in range(0, Globals.NUMREPLICAS):
	    if Globals.REPLICAS[i]['mac'] == '':
		arpRequest = Arps.create_arp_request(octstr_to_array(Globals.VMAC), ipstr_to_int(Globals.VIP), ipstr_to_int(Globals.REPLICAS[i]['ip']))
		self.Multipath.flood(None, arpRequest, openflow.OFPP_FLOOD, openflow.OFPP_CONTROLLER)
		
	self.post_callback(5, self.arpRequestReplicas)
Beispiel #6
0
def get_controller_dstrule(srcIP, srcWild, gateIP):
    flow = {}
    flow[DL_TYPE] = 0x0800
    flow[NW_SRC] = srcIP
    flow[NW_SRC_N_WILD] = srcWild
    flow[NW_DST] = ipstr_to_int(gateIP)
    actions = [
              [openflow.OFPAT_OUTPUT, [0, openflow.OFPP_CONTROLLER]]
              ]
    return (flow, actions, actions)
Beispiel #7
0
def actionDeleteRule(rule):
    Globals.INSTALLLOG.write("***Removing Rule: " + str(rule) + '\n')
    for i in range(0, Globals.NUMREPLICAS):
        if Globals.REPLICAS[i]['no'] == rule['replica']:
            (flow, defaultActions,
             rewriteActions) = IPs.get_forwarding_dstrule(
                 ipstr_to_int(rule['ip']), rule['wild'], Globals.VIP,
                 Globals.REPLICAS[i]['mac'], Globals.REPLICAS[i]['ip'],
                 Globals.REPLICAS[i]['port'])
            Multipath.delete_flow(flow, rule['replica'])
Beispiel #8
0
 def find_host_by_ipstr(self, nw_str):
     nw = ipstr_to_int(nw_str)
     info = {}
     
     for dp1, inport, dladdr,nwaddr,name in self.adjacency_hosts:
         if nwaddr == nw:
             info['dp'] = dp1
             info['port'] = inport
             info['dl_addr'] = dladdr
             return info
     
     return None
Beispiel #9
0
def actionTransitionRule(rule):
    Globals.INSTALLLOG.write("***Transition Rule: " + str(rule) + '\n')
    (flow, defaultActions,
     rewriteActions) = IPs.get_controller_dstrule(ipstr_to_int(rule['ip']),
                                                  rule['wild'], Globals.VIP)
    Multipath.install_controller_flow(flow, openflow.OFP_FLOW_PERMANENT,
                                      openflow.OFP_FLOW_PERMANENT,
                                      defaultActions, None,
                                      openflow.OFP_DEFAULT_PRIORITY, 0, None,
                                      rule['replica'], rewriteActions)
    Globals.COMPONENT.post_callback(Globals.HARD_TIMEOUT,
                                    lambda: hardTimeoutHandler(rule))
Beispiel #10
0
 def ipsrcrw_and_forward(self, dpid, inport, packet, buf, bufid):
     logger.info('IPSBF:[' + str(buf) + ']{' + str(packet) + '}\n')
     buf[26] = 10
     buf[27] = 0
     buf[28] = 0
     buf[29] = 5
     packet.next.srcip = ipstr_to_int('10.0.0.5')
     IPHeaderChecksum = (packet.next).checksum()
     buf[24] = IPHeaderChecksum >> 8
     buf[25] = IPHeaderChecksum & 0xFF
     logger.info('ChecksuM: ' + str(IPHeaderChecksum) + '\n')
     logger.info('IPSAF:[' + str(buf) + ']{' + str(packet) + '}\n')
     self.send_openflow(dpid, None, buf, 0, inport)
    def ipsrcrw_and_forward(self, dpid, inport, packet, buf, bufid):
        logger.info('IPSBF:[' + str(buf) + ']{' + str(packet) + '}\n')
        buf[26] = 10
        buf[27] = 0
        buf[28] = 0
        buf[29] = 5
        packet.next.srcip = ipstr_to_int('10.0.0.5')
        IPHeaderChecksum = (packet.next).checksum()
        buf[24] = IPHeaderChecksum >> 8
        buf[25] = IPHeaderChecksum & 0xFF
        logger.info('ChecksuM: ' + str(IPHeaderChecksum) + '\n')
        logger.info('IPSAF:[' + str(buf) + ']{' + str(packet) + '}\n')
	self.send_openflow(dpid, None, buf, 0, inport)
Beispiel #12
0
    def ipdstrw_and_forward(self, dpid, inport, packet, buf, bufid):
        logger.info('IPDBF:[' + str(buf) + ']{' + str(packet) + '}\n')
        buf[30] = 10
        buf[31] = 0
        buf[32] = 0
        buf[33] = 3
        packet.next.dstip = ipstr_to_int('10.0.0.3')
        IPHeaderChecksum = (packet.next).checksum()
        buf[24] = IPHeaderChecksum >> 8
        buf[25] = IPHeaderChecksum & 0xFF
        logger.info('Checksum: ' + str(IPHeaderChecksum) + '\n')
        logger.info('IPDAF:[' + str(buf) + ']{' + str(packet) + '}\n')

        # push down flow entry
        flow = {}
        flow[DL_TYPE] = 0x0800
        flow[NW_DST] = ipstr_to_int('10.0.0.5')
        actions = [[openflow.OFPAT_SET_NW_DST,
                    ipstr_to_int('10.0.0.3')], [openflow.OFPAT_OUTPUT, [0, 1]]]
        CACHE_TIMEOUT = 100
        self.install_datapath_flow(dpid, flow, CACHE_TIMEOUT,
                                   openflow.OFP_FLOW_PERMANENT, actions, None,
                                   openflow.OFP_DEFAULT_PRIORITY, inport, None)
Beispiel #13
0
def actionInstallRule(rule):
    Globals.INSTALLLOG.write("***Installing Rule: " + str(rule) + '\n')
    for i in range(0, Globals.NUMREPLICAS):
        if Globals.REPLICAS[i]['no'] == rule['replica']:
            (flow, defaultActions,
             rewriteActions) = IPs.get_forwarding_dstrule(
                 ipstr_to_int(rule['ip']), rule['wild'], Globals.VIP,
                 Globals.REPLICAS[i]['mac'], Globals.REPLICAS[i]['ip'],
                 Globals.REPLICAS[i]['port'])
            Multipath.install_replica_flow(flow, openflow.OFP_FLOW_PERMANENT,
                                           openflow.OFP_FLOW_PERMANENT,
                                           defaultActions, None,
                                           openflow.OFP_DEFAULT_PRIORITY, 0,
                                           None, rule['replica'],
                                           rewriteActions)
Beispiel #14
0
def get_microflow_dstrule(packet, dstMAC, dstIP, outport):
    currflow = extract_flow(packet)
    flow = {}
    flow[DL_TYPE] = 0x0800
    flow[NW_SRC] = currflow[NW_SRC]
    flow[NW_DST] = currflow[NW_DST]
    defaultActions = [
              [openflow.OFPAT_OUTPUT, [0, outport]]
              ]
    rewriteActions = [
              [openflow.OFPAT_SET_DL_DST, dstMAC],
              [openflow.OFPAT_SET_NW_DST, ipstr_to_int(dstIP)],
              [openflow.OFPAT_OUTPUT, [0, outport]]
              ]

    return (flow, defaultActions, rewriteActions)
Beispiel #15
0
    def foundMac(self, switchNum, mac, ip, inport):
        for i in range(0, Globals.NUMREPLICAS):
            if (ip == Globals.REPLICAS[i]['ip']) and Globals.REPLICAS[i]['mac'] == '':
                Globals.REPLICAS[i]['mac'] = mac
                Globals.REPLICAS[i]['port'] = inport
  
                for j, switchJ in enumerate(Globals.SWITCHES):
                    if switchJ['mac'] == switchNum:
                        Globals.log.info('Discovered MAC of replica w/IP: ' + ip + ' at switch # ' + str(switchJ['no']))
                        switchJ['replicas'].append(Globals.REPLICAS[i]['no'])
			flow = {}
			flow[DL_TYPE] = 0x0800
                        flow[NW_DST] = ipstr_to_int(ip)
                        actions = [[openflow.OFPAT_OUTPUT, [0, inport]]]
			Globals.COMPONENT.install_datapath_flow(switchNum, flow, openflow.OFP_FLOW_PERMANENT, openflow.OFP_FLOW_PERMANENT, actions, None, openflow.OFP_DEFAULT_PRIORITY + 10, openflow.OFPP_CONTROLLER, None)
                Globals.MACREPLICAUPDATE = True
Beispiel #16
0
    def packet_in_callback(self, dpid, inport, reason, len, bufid, packet):

        # Install initial setup forwarding rules
	if self.Init == True:
	    self.post_callback(Globals.PORT_STATS_PERIOD, lambda : self.port_timer())
	    self.Init = False

        # Controller Attention
	if reason == openflow.OFPR_ACTION:
	    self.myIPTransition.controllerAction(packet)

	# Incoming ARPs
	elif packet.type == Globals.ARP_TYPE:

	    # Response to our ARP requests 
	    # 1. Record MAC 
	    # 2. Install appropriate IP Forwarding Rule: Change dest VIP to dest Replica i
            if packet.dst == octstr_to_array(Globals.VMAC):
	        foundMacs = True
                for i in range(0, Globals.NUMREPLICAS):
	            if ((packet.next.protosrc == ipstr_to_int(Globals.REPLICAS[i]['ip'])) and (Globals.REPLICAS[i]['mac'] != mac_to_str(packet.src))):
		        Globals.REPLICAS[i]['mac'] = mac_to_str(packet.src)
			Globals.REPLICAS[i]['port'] = inport

			for j, switchJ in enumerate(Globals.SWITCHES):
			    if switchJ['mac'] == dpid:
				switchJ['replicas'].append(Globals.REPLICAS[i]['no'])

		    if (Globals.REPLICAS[i]['mac'] == ''):
		        foundMacs = False

	        if foundMacs == True and self.AllMacsFound == False:
		    Globals.log.info('REPLICAS ' + str(Globals.REPLICAS))
		    Globals.log.info('SWITCHES ' + str(Globals.SWITCHES))
		    Globals.log.info('\n')
		    Globals.log.info('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
		    rulePairList = self.myEvalRules.updateAlphas()
		    self.myIPTransition.installRules(rulePairList)
		    Globals.log.info('<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<')
		    Globals.log.info('\n')
		    self.AllMacsFound = True

    	    # Requests for VIP respond with ARP Response
   	    elif packet.next.protodst == ipstr_to_int(Globals.VIP):
		srcIP = ip_to_str(packet.next.protosrc)
	
		# IP Rules
		(flow, defaultActions, rewriteActions) = IPs.get_forwarding_srcrule(srcIP, mac_to_str(packet.src), Globals.VMAC, Globals.VIP, inport)
		self.Multipath.install_microflow_flow(flow, openflow.OFP_FLOW_PERMANENT, openflow.OFP_FLOW_PERMANENT, defaultActions, None, openflow.OFP_DEFAULT_PRIORITY, 0, None, dpid, inport, rewriteActions)

	        arpResponse = Arps.create_virtual_arp_response(packet, octstr_to_array(Globals.VMAC), ipstr_to_int(Globals.VIP))
                self.Multipath.send(dpid, None, arpResponse, [[openflow.OFPAT_OUTPUT, [0, inport]]], openflow.OFPP_CONTROLLER)

	    else:
		arpResponse = Arps.create_arp_response(packet)
		self.Multipath.send(dpid, None, arpResponse, [[openflow.OFPAT_OUTPUT, [0, inport]]], openflow.OFPP_CONTROLLER)

        elif packet.type == Globals.IP_TYPE:
	    Globals.log.info("Warning! S1 SHOULD NOT BE RECEIVING IP Traffic!!!")
#	    self.myIPTransition.controllerAction(packet)

        return CONTINUE
Beispiel #17
0
def host_to_ip(hostid):
    return ipstr_to_int("10.0.0." + str(hostid))
Beispiel #18
0
def actionDeleteRule(rule):
    Globals.INSTALLLOG.write("***Removing Rule: " + str(rule) + '\n')
    for i in range(0, Globals.NUMREPLICAS):
        if Globals.REPLICAS[i]['no'] == rule['replica']:
            (flow, defaultActions, rewriteActions) = IPs.get_forwarding_dstrule(ipstr_to_int(rule['ip']), rule['wild'], Globals.VIP, Globals.REPLICAS[i]['mac'], Globals.REPLICAS[i]['ip'], Globals.REPLICAS[i]['port'])
            Multipath.delete_flow(flow, rule['replica'])
Beispiel #19
0
def actionTransitionRule(rule):
    Globals.INSTALLLOG.write("***Transition Rule: " + str(rule) + '\n')
    (flow, defaultActions, rewriteActions) = IPs.get_controller_dstrule(ipstr_to_int(rule['ip']), rule['wild'], Globals.VIP)
    Multipath.install_controller_flow(flow, openflow.OFP_FLOW_PERMANENT, openflow.OFP_FLOW_PERMANENT, defaultActions, None, openflow.OFP_DEFAULT_PRIORITY, 0, None, rule['replica'], rewriteActions)
    Globals.COMPONENT.post_callback(Globals.HARD_TIMEOUT, lambda : hardTimeoutHandler(rule))
Beispiel #20
0
def actionInstallRule(rule):
    Globals.INSTALLLOG.write("***Installing Rule: " + str(rule) + '\n')
    for i in range(0, Globals.NUMREPLICAS):
        if Globals.REPLICAS[i]['no'] == rule['replica']:
            (flow, defaultActions, rewriteActions) = IPs.get_forwarding_dstrule(ipstr_to_int(rule['ip']), rule['wild'], Globals.VIP, Globals.REPLICAS[i]['mac'], Globals.REPLICAS[i]['ip'], Globals.REPLICAS[i]['port'])
	    Multipath.install_replica_flow(flow, openflow.OFP_FLOW_PERMANENT, openflow.OFP_FLOW_PERMANENT, defaultActions, None, openflow.OFP_DEFAULT_PRIORITY, 0, None, rule['replica'], rewriteActions)