Esempio n. 1
0
    private void acceptor(ref UdpPacket udp_p, ref Paxos_Packet paxos_p)
    {
        switch (paxos_p.MsgType)
        {
        case ((ushort)Phase.Paxos_1A):
            paxos_p.MsgType     = (ushort)Phase.Paxos_1B;
            paxos_p.Voted_Round = vrounds_register[paxos_p.Instance];
            paxos_p.Value       = value_register[paxos_p.Instance];
            paxos_p.Accept_ID   = datapath_id;
            rounds_register[paxos_p.Instance] = paxos_p.Voted_Round;
            udp_p.DestinationPort             = Paxos.Learner_Port;
            udp_p.UpdateUDPChecksum();
            break;

        case ((ushort)Phase.Paxos_2A):
            paxos_p.MsgType = (ushort)Phase.Paxos_2B;
            rounds_register[paxos_p.Instance]  = paxos_p.Round;
            vrounds_register[paxos_p.Instance] = paxos_p.Round;
            value_register[paxos_p.Instance]   = paxos_p.Value;
            paxos_p.Accept_ID     = datapath_id;
            udp_p.DestinationPort = Paxos.Learner_Port;
            udp_p.UpdateUDPChecksum();
            break;

        default:
            throw (new Exception("Unknown Paxos phase"));
        }
    }
Esempio n. 2
0
    override public ForwardingDecision process_packet(int in_port, ref Packet packet)
    {
        if (packet is EthernetPacket &&
            packet.Encapsulates(typeof(IPv4Packet), typeof(UdpPacket), typeof(Paxos_Packet)))
        {
            IpPacket  ip_p  = ((IpPacket)(packet.PayloadPacket));
            UdpPacket udp_p = ((UdpPacket)(ip_p.PayloadPacket));

            if (udp_p.DestinationPort == Paxos.Paxos_Coordinator_Port)
            {
                Paxos_Packet paxos_p = ((Paxos_Packet)(udp_p.PayloadPacket));

                instance_register++;
                paxos_p.Instance      = instance_register;
                udp_p.DestinationPort = Paxos.Paxos_Acceptor_Port;
                udp_p.UpdateUDPChecksum(); // NOTE we could use "udp_p.Checksum = 0" to
                                           //      follows the P4 implementation,
                                           //      avoiding the (optional) UDP checksum.
                                           //      Same applies to instances of
                                           //      checksum-setting below.
            }
        }

        // We assume that we receive from in_port and send to in_port+1.
        // NOTE that we implicitly forward all non-Paxos packets onwards,
        //      unmmodified. The downstream processor then decides how to forward
        //      them along the network.
        return(new ForwardingDecision.SinglePortForward(in_port + 1));
    }
Esempio n. 3
0
    override public ForwardingDecision process_packet(int in_port, ref Packet packet)
    {
        //Check if the packet is of the form we're interested in.
        if (packet is EthernetPacket &&
            packet.Encapsulates(typeof(IPv4Packet), typeof(UdpPacket), typeof(Paxos_Packet)))
        {
            IpPacket  ip_p  = ((IpPacket)(packet.PayloadPacket));
            UdpPacket udp_p = ((UdpPacket)(ip_p.PayloadPacket));

            if (udp_p.DestinationPort == Paxos.Paxos_Acceptor_Port)
            {
                Paxos_Packet paxos_p = ((Paxos_Packet)(udp_p.PayloadPacket));

                ingress_metadata_t local_metadata;
                read_round(out local_metadata, paxos_p);
                if (local_metadata.round <= paxos_p.Round)
                {
                    acceptor(ref udp_p, ref paxos_p);
                }
            }
        }

        // We follow the same forwarding policy as the Coordinator.
        return(new ForwardingDecision.SinglePortForward(in_port + 1));
    }
Esempio n. 4
0
 private void read_round(out ingress_metadata_t local_metadata, Paxos_Packet paxos_p)
 {
     local_metadata          = new ingress_metadata_t();
     local_metadata.round    = rounds_register[paxos_p.Instance];
     local_metadata.set_drop = true;
 }