Ejemplo n.º 1
0
 def gratuitousARP(self, vs):
     if vs is None:
         vswitches = self.net[0xaabbcc].vswitch
     else:
         vswitches = dict(only=vs)
     for k in vswitches.keys():
         v = vswitches[k]
         pkt_eth = pkt.ethernet(dst=pkt.ETHER_BROADCAST, src=v.hw_addr)
         pkt_eth.type = pkt.ethernet.VLAN_TYPE
         pkt_vlan = pkt.vlan(id=v.vstag)
         pkt_vlan.eth_type = pkt.ethernet.ARP_TYPE
         grat = pkt.arp()
         grat.opcode = pkt.arp.REQUEST
         grat.hwsrc = pkt_eth.src
         grat.hwdst = pkt_eth.dst
         grat.payload = b'\x0f' * 8
         pkt_eth.payload = pkt_vlan
         pkt_vlan.payload = grat
         dpid = self.net[0xaabbcc].getDPID(v)
         msg = of.ofp_packet_out(data=pkt_eth)
         msg.actions.append(of.ofp_action_output(port=v.uplink))
         try:
             conn = core.openflow.getConnection(dpid)
             self.log.debug("Sending gratuitousARP for %s" % v)
             conn.send(msg)
         except:
             raise RuntimeError("can't send msg to vSwitch %s" % v)
Ejemplo n.º 2
0
 def outbound2Network(self,event):
     remote_vstag = None
     remote_vs_hw = None
     vs_hw = self.avs[event.dpid].hw_addr
     uplink = self.avs[event.dpid].uplink
     packet = event.parsed
     eth = packet.find('ethernet')
     net_id = fromBytesToInt(getNetIDEthAddr(eth.src))
     hw_dst = removeNetIDEthAddr(eth.dst)
     (remote_vstag,remote_vs_hw) = self.net[net_id].getRemotevSwitchData(hw_dst)
     if remote_vstag is None:
         self.log.info("External packet to a unknown destination: %s" % eth.dst)
         return
     vlan = pkt.vlan(id=remote_vstag, eth_type=pkt.ethernet.HOTOM_TYPE)
     hotom = pkt.hotom()
     hotom.net_id = net_id
     hotom.dst = eth.dst
     hotom.src = eth.src
     eth.src = vs_hw
     eth.dst = remote_vs_hw
     hotom.payload = eth.payload
     vlan.payload = hotom
     eth.payload = vlan
     eth.type = pkt.ethernet.VLAN_TYPE
     self.send(event.dpid,eth,uplink)
Ejemplo n.º 3
0
 def sendPktExternal(self, dpid, pkt_eth):
     self.log.debug("Entering sendPktExternal")
     self.log.debug("    => Eth   Pkt %s" % (pkt_eth))
     vswitches = self.net[0xaabbcc].vswitch
     vstag = vswitches[dpid].vstag
     port = vswitches[dpid].uplink
     dst_vswitch = None
     dst_addr = removeNetIDEthAddr(pkt_eth.dst)
     for i in vswitches.keys():
         vswitch = vswitches[i]
         for k in vswitch._vm.keys():
             vm = vswitch._vm[k]
             if dst_addr == vm.hw_addr:
                 dst_vswitch = vswitch
     if dst_vswitch is None:
         self.log.debug("External packet to a unknown destination: %s" %
                        pkt_eth.dst)
         return
     pkt_vlan = pkt.vlan(id=dst_vswitch.vstag,
                         eth_type=pkt.ethernet.HOTOM_TYPE)
     pkt_hotom = pkt.hotom()
     pkt_hotom.net_id = 0xaabbcc
     pkt_hotom.dst = pkt_eth.dst
     pkt_hotom.src = pkt_eth.src
     pkt_eth.src = vswitches[dpid].hw_addr
     pkt_eth.dst = dst_vswitch.hw_addr
     pkt_hotom.payload = pkt_eth.payload
     pkt_vlan.payload = pkt_hotom
     pkt_eth.type = pkt.ethernet.VLAN_TYPE
     pkt_eth.payload = pkt_vlan
     self.log.debug("Sending port %d %s" % (port, pkt_eth))
     self.log.debug("    => HotOM Pkt %s" % (pkt_hotom))
     self.sendPktInternal(dpid, pkt_eth, port)
Ejemplo n.º 4
0
 def sendPktExternal(self,dpid,pkt_eth):
     self.log.debug("Entering sendPktExternal")
     self.log.debug("    => Eth   Pkt %s" % (pkt_eth))
     vswitches = self.net[0xaabbcc].vswitch
     vstag = vswitches[dpid].vstag
     port = vswitches[dpid].uplink
     dst_vswitch = None
     dst_addr = removeNetIDEthAddr(pkt_eth.dst)
     for i in vswitches.keys():
         vswitch = vswitches[i]
         for k in vswitch._vm.keys():
             vm = vswitch._vm[k]
             if dst_addr == vm.hw_addr:
                 dst_vswitch = vswitch
     if dst_vswitch is None:
         self.log.debug("External packet to a unknown destination: %s" % pkt_eth.dst)
         return
     pkt_vlan = pkt.vlan(id=dst_vswitch.vstag,eth_type=pkt.ethernet.HOTOM_TYPE)
     pkt_hotom = pkt.hotom()
     pkt_hotom.net_id = 0xaabbcc
     pkt_hotom.dst = pkt_eth.dst
     pkt_hotom.src = pkt_eth.src
     pkt_eth.src = vswitches[dpid].hw_addr
     pkt_eth.dst = dst_vswitch.hw_addr
     pkt_hotom.payload = pkt_eth.payload
     pkt_vlan.payload = pkt_hotom
     pkt_eth.type = pkt.ethernet.VLAN_TYPE
     pkt_eth.payload = pkt_vlan
     self.log.debug("Sending port %d %s" % (port,pkt_eth))
     self.log.debug("    => HotOM Pkt %s" % (pkt_hotom))
     self.sendPktInternal(dpid,pkt_eth,port) 
Ejemplo n.º 5
0
 def gratuitousARP(self,vs):
     if vs is None:
         vswitches = self.net[0xaabbcc].vswitch
     else:
         vswitches = dict(only=vs)
     for k in vswitches.keys():
         v = vswitches[k]
         pkt_eth = pkt.ethernet(dst=pkt.ETHER_BROADCAST,src=v.hw_addr)
         pkt_eth.type = pkt.ethernet.VLAN_TYPE
         pkt_vlan = pkt.vlan(id=v.vstag)
         pkt_vlan.eth_type = pkt.ethernet.ARP_TYPE
         grat = pkt.arp()
         grat.opcode = pkt.arp.REQUEST
         grat.hwsrc = pkt_eth.src
         grat.hwdst = pkt_eth.dst
         grat.payload = b'\x0f' * 8
         pkt_eth.payload=pkt_vlan
         pkt_vlan.payload=grat
         dpid = self.net[0xaabbcc].getDPID(v)
         msg = of.ofp_packet_out(data=pkt_eth)
         msg.actions.append(of.ofp_action_output(port = v.uplink))
         try:
             conn = core.openflow.getConnection(dpid)
             self.log.debug("Sending gratuitousARP for %s" % v)
             conn.send(msg)
         except:
             raise RuntimeError("can't send msg to vSwitch %s" % v)
Ejemplo n.º 6
0
 def outbound2Network(self, event):
     remote_vstag = None
     remote_vs_hw = None
     vs_hw = self.avs[event.dpid].hw_addr
     uplink = self.avs[event.dpid].uplink
     packet = event.parsed
     eth = packet.find('ethernet')
     net_id = fromBytesToInt(getNetIDEthAddr(eth.src))
     hw_dst = removeNetIDEthAddr(eth.dst)
     (remote_vstag,
      remote_vs_hw) = self.net[net_id].getRemotevSwitchData(hw_dst)
     if remote_vstag is None:
         self.log.info("External packet to a unknown destination: %s" %
                       eth.dst)
         return
     vlan = pkt.vlan(id=remote_vstag, eth_type=pkt.ethernet.HOTOM_TYPE)
     hotom = pkt.hotom()
     hotom.net_id = net_id
     hotom.dst = eth.dst
     hotom.src = eth.src
     eth.src = vs_hw
     eth.dst = remote_vs_hw
     hotom.payload = eth.payload
     vlan.payload = hotom
     eth.payload = vlan
     eth.type = pkt.ethernet.VLAN_TYPE
     self.send(event.dpid, eth, uplink)
Ejemplo n.º 7
0
    def packet_to_network(self, packet):
        self.trace("packet_to_network: packet=%s\n" % packet, timeStamped=True)
        
        if len(packet["raw"]) == 0:
            if packet["ethtype"] == packetlib.ethernet.ARP_TYPE:
                p_begin = p = self.make_arp(packet)
            else:  # BLANK PACKET FOR NOW - MAY NEED TO SUPPORT OTHER PACKETS LATER
                p_begin = p = packetlib.ethernet()
        else:
            p_begin = p = packetlib.ethernet(packet["raw"])

        # ETHERNET PACKET IS OUTERMOST
        p.src = packet["srcmac"]
        p.dst = packet["dstmac"]

        if 'vlan_id' in packet:
            if isinstance(p.next, packetlib.vlan):
                p = p.next
            else:
                # Make a vlan header
                old_eth_type = p.type
                p.type = 0x8100
                p.next = packetlib.vlan(next=p.next)
                p = p.next
                p.eth_type = old_eth_type
            p.id = packet['vlan_id']
            p.pcp = packet['vlan_pcp']
        else:
            if isinstance(p.next, packetlib.vlan):
                p.type = p.next.eth_type # Restore encapsulated eth type
                p.next = p.next.next # Remove vlan from header

        # GET PACKET INSIDE ETHERNET/VLAN
        p = p.next
        if isinstance(p, packetlib.ipv4):
            p.srcip = packet["srcip"]
            p.dstip = packet["dstip"]
            p.protocol = packet["protocol"]
            p.tos = packet["tos"]

            p = p.next
            if isinstance(p, packetlib.udp) or isinstance(p, packetlib.tcp):
                p.srcport = packet["srcport"]
                p.dstport = packet["dstport"]
            elif isinstance(p, packetlib.icmp):
                p.type = packet["srcport"]
                p.code = packet["dstport"]

        elif isinstance(p, packetlib.arp):
            if 'vlan_id' in packet:
                p.opcode = packet["protocol"]
                p.protosrc = packet["srcip"]
                p.protodst = packet["dstip"]
            else:
                p_begin = self.make_arp(packet)
        
        return p_begin.pack()
Ejemplo n.º 8
0
    def packet_to_network(self, packet):
        if len(packet["raw"]) == 0:
            if packet["ethtype"] == packetlib.ethernet.ARP_TYPE:
                p_begin = p = self.make_arp(packet)
            else:  # BLANK PACKET FOR NOW - MAY NEED TO SUPPORT OTHER PACKETS LATER
                p_begin = p = packetlib.ethernet()
        else:
            p_begin = p = packetlib.ethernet(packet["raw"])

        # ETHERNET PACKET IS OUTERMOST
        p.src = packet["srcmac"]
        p.dst = packet["dstmac"]

        if 'vlan_id' in packet:
            if isinstance(p.next, packetlib.vlan):
                p = p.next
            else:
                # Make a vlan header
                old_eth_type = p.type
                p.type = 0x8100
                p.next = packetlib.vlan(next=p.next)
                p = p.next
                p.eth_type = old_eth_type
            p.id = packet['vlan_id']
            p.pcp = packet['vlan_pcp']
        else:
            if isinstance(p.next, packetlib.vlan):
                p.type = p.next.eth_type  # Restore encapsulated eth type
                p.next = p.next.next  # Remove vlan from header

        # GET PACKET INSIDE ETHERNET/VLAN
        p = p.next
        if isinstance(p, packetlib.ipv4):
            p.srcip = packet["srcip"]
            p.dstip = packet["dstip"]
            p.protocol = packet["protocol"]
            p.tos = packet["tos"]

            p = p.next
            if isinstance(p, packetlib.udp) or isinstance(p, packetlib.tcp):
                p.srcport = packet["srcport"]
                p.dstport = packet["dstport"]
            elif isinstance(p, packetlib.icmp):
                p.type = packet["srcport"]
                p.code = packet["dstport"]

        elif isinstance(p, packetlib.arp):
            if 'vlan_id' in packet:
                p.opcode = packet["protocol"]
                p.protosrc = packet["srcip"]
                p.protodst = packet["dstip"]
            else:
                p_begin = self.make_arp(packet)

        return p_begin.pack()
Ejemplo n.º 9
0
    def packet_to_pox(self, packet):
        if len(packet["payload"]) == 0:
            return self.make_pox_arp(packet).pack()

        p_begin = p = packetlib.ethernet(packet["payload"])

        # ETHERNET PACKET IS OUTERMOST
        p.src = packetaddr.EthAddr(packet["srcmac"].to_bytes())
        p.dst = packetaddr.EthAddr(packet["dstmac"].to_bytes())

        # DEAL WITH ETHERNET VLANS
        diff = get_packet_diff(packet)
        if diff:
            if isinstance(p.next, packetlib.vlan):
                p = p.next
            else:
                # Make a vlan header
                old_eth_type = p.type
                p.type = 0x8100
                p.next = packetlib.vlan(next=p.next)
                p = p.next
                p.eth_type = old_eth_type
            p.id, p.pcp = self.vlan_from_diff(diff)
        else:
            if isinstance(p.next, packetlib.vlan):
                p.type = p.next.eth_type # Restore encapsulated eth type
                p.next = p.next.next # Remove vlan from header

        # GET PACKET INSIDE ETHERNET/VLAN
        p = p.next
        if isinstance(p, packetlib.ipv4):
            p.srcip = packetaddr.IPAddr(packet["srcip"].to_bytes())
            p.dstip = packetaddr.IPAddr(packet["dstip"].to_bytes())
            p.protocol = packet["protocol"]
            p.tos = packet["tos"]

            p = p.next
            if isinstance(p, packetlib.udp) or isinstance(p, packetlib.tcp):
                p.srcport = packet["srcport"]
                p.dstport = packet["dstport"]
            elif isinstance(p, packetlib.icmp):
                p.type = packet["srcport"]
                p.code = packet["dstport"]

        elif isinstance(p, packetlib.arp):
            if diff:
                p.opcode = packet["protocol"]
                p.protosrc = packetaddr.IPAddr(packet["srcip"].to_bytes())
                p.protodst = packetaddr.IPAddr(packet["dstip"].to_bytes())
            else:
                p_begin = self.make_pox_arp(packet)
        
        return p_begin.pack()
Ejemplo n.º 10
0
 def createGratuitousARP(self):
     eth = pkt.ethernet(dst=pkt.ETHER_BROADCAST,src=self.hw_addr)
     eth.type = pkt.ethernet.VLAN_TYPE
     vlan = pkt.vlan(id=self.vstag)
     vlan.eth_type = pkt.ethernet.ARP_TYPE
     grat = pkt.arp()
     grat.opcode = pkt.arp.REQUEST
     grat.hwsrc = eth.src
     grat.hwdst = eth.dst
     grat.payload = b'\x0f' * 8
     eth.payload=vlan
     vlan.payload=grat
     return eth
Ejemplo n.º 11
0
 def createGratuitousARP(self):
     eth = pkt.ethernet(dst=pkt.ETHER_BROADCAST, src=self.hw_addr)
     eth.type = pkt.ethernet.VLAN_TYPE
     vlan = pkt.vlan(id=self.vstag)
     vlan.eth_type = pkt.ethernet.ARP_TYPE
     grat = pkt.arp()
     grat.opcode = pkt.arp.REQUEST
     grat.hwsrc = eth.src
     grat.hwdst = eth.dst
     grat.payload = b'\x0f' * 8
     eth.payload = vlan
     vlan.payload = grat
     return eth
Ejemplo n.º 12
0
 def push_header(self,packet,port):
     pkt_eth = packet.find('ethernet')
     pkt_hotom = pkt.hotom()
     pkt_hotom.net_id = 0x0
     pkt_hotom.dst = pkt_eth.dst
     pkt_hotom.dst = pkt_eth.src
     pkt_vlan = pkt.vlan(id=2,eth_type=pkt.ethernet.HOTOM_TYPE)
     pkt_ip = packet.find('ipv4')
     if pkt_ip is None:
         self.log.debug("Packet not IPV4: %s" % packet)
         return
     pkt_hotom.payload = pkt_ip
     pkt_vlan.payload = pkt_hotom
     pkt_eth.payload = pkt_vlan
     pkt_eth.type = pkt.ethernet.VLAN_TYPE
     msg = of.ofp_packet_out(data=pkt_eth)
     msg.actions.append(of.ofp_action_output(port = port))
     return msg
Ejemplo n.º 13
0
 def push_header(self, packet, port):
     pkt_eth = packet.find('ethernet')
     pkt_hotom = pkt.hotom()
     pkt_hotom.net_id = 0x0
     pkt_hotom.dst = pkt_eth.dst
     pkt_hotom.dst = pkt_eth.src
     pkt_vlan = pkt.vlan(id=2, eth_type=pkt.ethernet.HOTOM_TYPE)
     pkt_ip = packet.find('ipv4')
     if pkt_ip is None:
         self.log.debug("Packet not IPV4: %s" % packet)
         return
     pkt_hotom.payload = pkt_ip
     pkt_vlan.payload = pkt_hotom
     pkt_eth.payload = pkt_vlan
     pkt_eth.type = pkt.ethernet.VLAN_TYPE
     msg = of.ofp_packet_out(data=pkt_eth)
     msg.actions.append(of.ofp_action_output(port=port))
     return msg
Ejemplo n.º 14
0
 def outboundToRemoteVM(self,eth,net_id,dst_vstag):
     dst_eth = getEthAddrFromVstag(dst_vstag)
     # Create HotOM header from original frame
     hotom = pkt.hotom()
     hotom.net_id = net_id
     hotom.dst = eth.dst
     hotom.src = eth.src
     hotom.type = pkt.hotom.IP_TYPE
     hotom.payload = eth.payload
     # Create VLAN header
     vlan = pkt.vlan(id=dst_vstag, eth_type=pkt.ethernet.HOTOM_TYPE)
     # Replace ethernet addresses and encapsulate
     eth.src = self.hw_addr
     eth.dst = dst_eth
     eth.type = pkt.ethernet.VLAN_TYPE
     vlan.payload = hotom
     eth.payload = vlan
     self.send(eth,self.uplink)