forked from tkn-tub/ns3-gym
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mygym.h
78 lines (64 loc) · 2.3 KB
/
mygym.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2018 Technische Universität Berlin
*
* 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: Piotr Gawlowicz <[email protected]>
*/
#ifndef MY_GYM_ENTITY_H
#define MY_GYM_ENTITY_H
#include "ns3/stats-module.h"
#include "ns3/opengym-module.h"
#include "ns3/spectrum-module.h"
namespace ns3 {
class Node;
class WifiMacQueue;
class Packet;
class MyGymEnv : public OpenGymEnv
{
public:
MyGymEnv ();
MyGymEnv (uint32_t channelNum);
virtual ~MyGymEnv ();
static TypeId GetTypeId (void);
virtual void DoDispose ();
Ptr<OpenGymSpace> GetActionSpace();
Ptr<OpenGymSpace> GetObservationSpace();
bool GetGameOver();
Ptr<OpenGymDataContainer> GetObservation();
float GetReward();
std::string GetExtraInfo();
bool ExecuteActions(Ptr<OpenGymDataContainer> action);
// the function has to be static to work with MakeBoundCallback
// that is why we pass pointer to MyGymEnv instance to be able to store the context (node, etc)
static void PerformCca(Ptr<MyGymEnv> entity, uint32_t channelId, Ptr<const SpectrumValue> avgPowerSpectralDensity);
void CollectChannelOccupation(uint32_t chanId, uint32_t occupied);
bool CheckIfReady();
void ClearObs();
private:
void ScheduleNextStateRead();
Ptr<WifiMacQueue> GetQueue(Ptr<Node> node);
bool SetCw(Ptr<Node> node, uint32_t cwMinValue=0, uint32_t cwMaxValue=0);
Time m_interval = Seconds(0.1);
Ptr<Node> m_currentNode;
uint64_t m_rxPktNum;
uint32_t m_channelNum;
std::vector<uint32_t> m_channelOccupation;
uint32_t m_currentChannel;
uint32_t m_collisionTh;
std::vector<uint32_t> m_collisions = {0,0,0,0,0,0,0,0,0,0,};
};
}
#endif // MY_GYM_ENTITY_H