Skip to content
Snippets Groups Projects
traci-node-lifecycle.h 2.93 KiB
Newer Older
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
 * Copyright (c) 2016 Fraunhofer ESK
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation;
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Author:Karsten Roscher <karsten.roscher@esk.fraunhofer.de>
 */
#ifndef TRACI_NODE_LIFECYCLE_H
#define TRACI_NODE_LIFECYCLE_H

#include <map>
#include <string>

#include "ns3/ptr.h"
#include "ns3/node.h"
#include "ns3/event-id.h"
#include "ns3/random-variable-stream.h"

#include "traci-node-manager.h"

namespace ns3
{

class TraCiNodeLifecyclePolicy
{

public:

  /*!
   * @brief Create policy.
   */
  TraCiNodeLifecyclePolicy ();

  /*!
   * @brief Destructor of the policy.
   */
  virtual ~TraCiNodeLifecyclePolicy ();

  /**
   * @brief Set random startup delay.
   *
   * @param rand Pointer to a random variable stream.
   */
  void
  SetRandomActivationDelay (Ptr<RandomVariableStream> rand);

  /**
   * @brief Set the earliest activation time.
   *
   * Nodes won't be started before this time. If a random activation
   * delay is set, it will be added to this time to avoid synchronized
   * start at that time.
   *
   * @param startTime	Earliest start time for nodes
   */
  void
  SetEarliestActivationTime (Time startTime);

  /*!
   * @brief Handle node activation via TraCI
   * @param node	Node to activate
   * @param vehicle	Vehicle instance assigned
   */
  void
  HandleActivateNode (Ptr<Node> node, Ptr<traci::Vehicle> vehicle);

  /*!
   * @brief Handle node shutdown via TraCI.
   * @param node	Node to deactivate
   */
  void
  HandleShutdownNode (Ptr<Node> node);

private:

  /*!
   * @brief Handle delayed activation of a node.
   * @param node	Node to activate.
   */
  void
  HandleDelayedActivation (Ptr<Node> node);

  /**
   * Pointer to a random variable stream modeling a random delay
   * before the node is activated from a life cycle perspective.
   * for an ezC2X stack installation.
   */
  Ptr<RandomVariableStream>
  m_randomDelay;

  //! Map of nodes waiting for activation
  typedef std::map<Ptr<Node>, EventId> ActivationMap;

  //! Nodes waiting for activation.
  ActivationMap m_waitingNodes;

  //! Earliest activation time.
  Time m_earliestActivationTime;
};

/*!
 * @brief Node manager controlling the node life cycle (via NodeLifecycleManager).
 */
typedef TraCiNodeManager<TraCiNodeLifecyclePolicy> TraCiNodeLifecycleManager;

}  // namespace ns3


#endif /* TRACI_NODE_LIFECYCLE_H */