def get_in_port(msg):
    """
    Get in_port from packet_in msg.
    """
    for field in msg.match.fields:
        if field.header == msg.datapath.ofproto.OXM_OF_IN_PORT:
            return field.value

    raise KeyError("in_port field not found.{0}".format(msg.match))