Exemplo n.º 1
0
    def _learn_arp_entry(self, ev):
        """
        Learn action to process PacketIn DHCP packets, dhcp ack packets will
        be used to learn the ARP entry for the UE to install rules in the arp
        table. The DHCP packets will then be sent thorugh the pipeline.
        """
        msg = ev.msg

        if self._dhcp_learn_scratch != msg.table_id:
            # Intended for other application
            return

        try:
            encoded_imsi = _get_encoded_imsi_from_packetin(msg)
            # Decode the imsi to properly save in directoryd
            imsi = decode_imsi(encoded_imsi)
        except MagmaOFError as e:
            # No packet direction, but intended for this table
            self.logger.error("Error obtaining IMSI from pkt-in: %s", e)
            return

        pkt = packet.Packet(msg.data)
        dhcp_header = pkt.get_protocols(dhcp.dhcp)[0]
        # DHCP yiaddr is the client(UE) ip addr
        #      chaddr is the client mac address
        self.add_arp_response_flow(imsi, dhcp_header.yiaddr, dhcp_header.chaddr)
Exemplo n.º 2
0
 def _assert_conversion(self, imsi):
     """
     To test the validity of the conversion, we can encode the imsi and
     decode to see if the two values match
     """
     test_val = decode_imsi(encode_imsi(imsi))
     self.assertEqual(imsi, test_val)
Exemplo n.º 3
0
 def check_imsi_metadata(self, flow, ue_req):
     """ Checks that IMSI set in the flow metadata matches the one sent """
     sent_imsi = 'IMSI' + ''.join([str(i) for i in ue_req.imsi])
     imsi_action = next((a for a in flow["instructions"][0]["actions"]
                         if a["field"] == "metadata"), None)
     self.assertIsNotNone(imsi_action)
     imsi64 = imsi_action["value"]
     # Convert between compacted uint IMSI and string
     received_imsi = decode_imsi(imsi64)
     self.assertEqual(sent_imsi, received_imsi,
                      "IMSI set in metadata field does not match sent IMSI")
Exemplo n.º 4
0
def _get_sid(flow):
    if IMSI_REG not in flow.match:
        return None
    return decode_imsi(flow.match[IMSI_REG])
Exemplo n.º 5
0
def _get_sid(flow):
    return decode_imsi(flow.match[IMSI_REG])
Exemplo n.º 6
0
 def get_sid(match):
     encoded_imsi = match.get(IMSI_REG)
     if encoded_imsi is None or encoded_imsi == 0:
         raise ValueError('IMSI could not be parsed from match')
     return decode_imsi(encoded_imsi)