void process::initialize(float exec_time,int beta) //should not be in constructor... max_pid can be affected
 {
	p_id=max_pid++;
	set_arvl_time();
 	set_execution_time(exec_time);
 	set_deadline(beta);// should be called after set_execution_time(---)
 }
Node::Node(std::string _name, int _scale, int _wcet, int _deadline) {
	name = _name;
	scale = _scale;

	set_wcet(_wcet);
	set_deadline(_deadline);

	unitNodes = NULL;
	granNodes = NULL;
}
Example #3
0
int
client_query(struct ntp_peer *p)
{
    int	val;

    if (p->addr == NULL && client_nextaddr(p) == -1) {
        set_next(p, MAX(SETTIME_TIMEOUT,
                        scale_interval(INTERVAL_QUERY_AGGRESSIVE)));
        return (0);
    }

    if (p->state < STATE_DNS_DONE || p->addr == NULL)
        return (-1);

    if (p->query->fd == -1) {
        struct sockaddr *sa = (struct sockaddr *)&p->addr->ss;

        if ((p->query->fd = socket(p->addr->ss.ss_family, SOCK_DGRAM,
                                   0)) == -1)
            fatal("client_query socket");

#ifdef HAVE_RTABLE
        if (p->rtable != -1 &&
                setsockopt(p->query->fd, SOL_SOCKET, SO_RTABLE,
                           &p->rtable, sizeof(p->rtable)) == -1)
            fatal("client_query setsockopt SO_RTABLE");
#endif

        if (connect(p->query->fd, sa, SA_LEN(sa)) == -1) {
            if (errno == ECONNREFUSED || errno == ENETUNREACH ||
                    errno == EHOSTUNREACH || errno == EADDRNOTAVAIL) {
                client_nextaddr(p);
                set_next(p, MAX(SETTIME_TIMEOUT,
                                scale_interval(INTERVAL_QUERY_AGGRESSIVE)));
                return (-1);
            } else
                fatal("client_query connect");
        }
        val = IPTOS_LOWDELAY;
        if (p->addr->ss.ss_family == AF_INET && setsockopt(p->query->fd,
                IPPROTO_IP, IP_TOS, &val, sizeof(val)) == -1)
            log_warn("setsockopt IPTOS_LOWDELAY");
        val = 1;
        if (setsockopt(p->query->fd, SOL_SOCKET, SO_TIMESTAMP,
                       &val, sizeof(val)) == -1)
            fatal("setsockopt SO_TIMESTAMP");
    }

    /*
     * Send out a random 64-bit number as our transmit time.  The NTP
     * server will copy said number into the originate field on the
     * response that it sends us.  This is totally legal per the SNTP spec.
     *
     * The impact of this is two fold: we no longer send out the current
     * system time for the world to see (which may aid an attacker), and
     * it gives us a (not very secure) way of knowing that we're not
     * getting spoofed by an attacker that can't capture our traffic
     * but can spoof packets from the NTP server we're communicating with.
     *
     * Save the real transmit timestamp locally.
     */

    p->query->msg.xmttime.int_partl = arc4random();
    p->query->msg.xmttime.fractionl = arc4random();
    p->query->xmttime = gettime_corrected();

    if (ntp_sendmsg(p->query->fd, NULL, &p->query->msg) == -1) {
        p->senderrors++;
        set_next(p, INTERVAL_QUERY_PATHETIC);
        p->trustlevel = TRUSTLEVEL_PATHETIC;
        return (-1);
    }

    p->senderrors = 0;
    p->state = STATE_QUERY_SENT;
    set_deadline(p, QUERYTIME_MAX);

    return (0);
}