Esempio n. 1
0
 def set_header_vlan(self, vlan_id=1, **kwargs):
     """
     Build a Dot1Q scapy object inside instance packet_data structure
     :param vlan_id: The VLAN ID
     :param kwargs: Extra params per scapy usage
     :return: None
     """
     self.packet_data['vlan'] = [
         inet.Dot1Q(vlan=vlan_id, **kwargs),
         inet.Dot1Q(vlan=vlan_id, **kwargs)
     ]
Esempio n. 2
0
 def _build_packet_header(self, reverse=False):
     """
     Build a packet header based on traffic profile using scapy external
     libraries.
     :param reverse: Swap source and destination info when building header
     :return: packet header in hex
     """
     srcmac = self._params['traffic']['l2'][
         'srcmac'] if not reverse else self._params['traffic']['l2'][
             'dstmac']
     dstmac = self._params['traffic']['l2'][
         'dstmac'] if not reverse else self._params['traffic']['l2'][
             'srcmac']
     srcip = self._params['traffic']['l3'][
         'srcip'] if not reverse else self._params['traffic']['l3']['dstip']
     dstip = self._params['traffic']['l3'][
         'dstip'] if not reverse else self._params['traffic']['l3']['srcip']
     layer2 = inet.Ether(src=srcmac, dst=dstmac)
     layer3 = inet.IP(src=srcip,
                      dst=dstip,
                      proto=self._params['traffic']['l3']['proto'])
     layer4 = inet.UDP(sport=self._params['traffic']['l4']['srcport'],
                       dport=self._params['traffic']['l4']['dstport'])
     if self._params['traffic']['vlan']['enabled']:
         vlan = inet.Dot1Q(vlan=self._params['traffic']['vlan']['id'],
                           prio=self._params['traffic']['vlan']['priority'],
                           id=self._params['traffic']['vlan']['cfi'])
     else:
         vlan = None
     packet = layer2 / vlan / layer3 / layer4 if vlan else layer2 / layer3 / layer4
     packet_bytes = bytes(packet)
     packet_hex = '0x' + binascii.hexlify(packet_bytes).decode('utf-8')
     return packet_hex