예제 #1
0
    //Send the specified packet.
    public virtual bool send(Packet packet)
    {
        string mac;

        //if the arp table has record of the dest mac
        if (arpTable.TryGetValue(packet.internet.getIP("dest"), out mac))
        {
            Debug.Log("PORT: Sending packet through cable");
            packet.netAccess.setMAC(mac, "dest");
        }

        //else if it is a broadcast mac or if it is a dhcp packet
        else if (packet.netAccess.getMAC("dest").Equals("FF:FF:FF:FF:FF:FF") || packet.GetComponent <DHCP>())
        {
            Debug.Log("PORT: Sending packet through cable");
        }
        //else if the device is a switch and it doesnt have an arp table, just check the mac address only
        else if (device.Equals("switch") && packet.netAccess.getMAC("dest").Equals(this.mac))
        {
            Debug.Log("PORT: Sending packet through cable");
        }
        else
        {
            Debug.LogAssertion("PORT: ERROR FINDING MAC ADDRESS BINDING");
            return(false);
        }


        /*while(Animate(packet))
         * {
         *
         * }*/
        //tag packet with vlan
        if (link.type.Equals("trunk"))
        {
            if (packet.gameObject.GetComponent <Link>())
            {
                packet.gameObject.GetComponent <Link>().type = link.type;
                packet.gameObject.GetComponent <Link>().vlan = link.vlan;
            }
            else
            {
                packet.gameObject.AddComponent <Link>();
                packet.gameObject.GetComponent <Link>().type = link.type;
                packet.gameObject.GetComponent <Link>().vlan = link.vlan;
            }
        }
        if (connected)
        {
            return(cable.send(packet, this));
        }
        else
        {
            return(false);
        }
    }