def may_add_vlan(packet, vlan_id):
    if vlan_id is None:
        return

    e = packet.protocols[0]
    assert isinstance(e, ethernet.ethernet)
    v = vlan.vlan(0, 0, vlan_id, e.ethertype)
    e.ethertype = ether.ETH_TYPE_8021Q
    packet.add_protocol(v)
:type packet: ryu.lib.packet.packet.Packet
dataset/ETHPy150Open osrg/ryu/ryu/services/protocols/vrrp/utils.py/may_add_vlan