nrf_subscription.cpp 6.22 KB
Newer Older
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
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
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
 * the OAI Public License, Version 1.1  (the "License"); you may not use this
 * file except in compliance with the License. You may obtain a copy of the
 * License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */

/*! \file nrf_subscription.cpp
 \brief
 \author  Tien-Thinh NGUYEN
 \company Eurecom
 \date 2020
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
27
 \email: Tien-Thinh.Nguyen@eurecom.fr
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
28
29
30
 */

#include "nrf_subscription.hpp"
31
32

#include <boost/date_time/posix_time/time_formatters.hpp>
33
#include <nlohmann/json.hpp>
34

35
#include "logger.hpp"
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
36
37
38
39

using namespace oai::nrf::app;

//------------------------------------------------------------------------------
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
40
void nrf_subscription::set_subscription_id(const std::string& sub) {
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
41
42
43
44
  subscription_id = sub;
}

//------------------------------------------------------------------------------
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
45
void nrf_subscription::get_subscription_id(std::string& sub) const {
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
46
47
48
49
50
51
52
53
  sub = subscription_id;
}

//------------------------------------------------------------------------------
std::string nrf_subscription::get_subscription_id() const {
  return subscription_id;
}

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
54
//------------------------------------------------------------------------------
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
55
void nrf_subscription::set_notification_uri(
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
56
    const std::string& notification_uri) {
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
57
58
59
  nf_status_notification_uri = notification_uri;
}

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
60
//------------------------------------------------------------------------------
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
61
void nrf_subscription::get_notification_uri(
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
62
    std::string& notification_uri) const {
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
63
64
65
  notification_uri = nf_status_notification_uri;
}

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
66
//------------------------------------------------------------------------------
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
67
void nrf_subscription::set_sub_condition(const subscription_condition_t& c) {
68
  sub_condition = c;
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
69
70
}

71
//------------------------------------------------------------------------------
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
72
void nrf_subscription::get_sub_condition(subscription_condition_t& c) const {
73
  c = sub_condition;
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
74
}
75

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
76
//------------------------------------------------------------------------------
77
/*
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
78
79
80
81
subscription_condition_t nrf_subscription::get_sub_condition() const {
  return sub_condition;
}
*/
82
83

//------------------------------------------------------------------------------
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
84
void nrf_subscription::set_notif_events(const std::vector<uint8_t>& ev_types) {
85
86
87
88
  notif_events = ev_types;
}

//------------------------------------------------------------------------------
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
89
void nrf_subscription::add_notif_event(const uint8_t& ev_type) {
90
91
92
93
  notif_events.push_back(ev_type);
}

//------------------------------------------------------------------------------
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
94
void nrf_subscription::get_notif_events(std::vector<uint8_t>& ev_types) const {
95
96
97
98
99
100
101
102
  ev_types = notif_events;
}

//------------------------------------------------------------------------------
std::vector<uint8_t> nrf_subscription::get_notif_events() const {
  return notif_events;
}

103
//------------------------------------------------------------------------------
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
104
void nrf_subscription::set_validity_time(const boost::posix_time::ptime& t) {
105
106
107
108
  validity_time = t;
}

//------------------------------------------------------------------------------
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
109
void nrf_subscription::get_validity_time(boost::posix_time::ptime& t) const {
110
111
112
113
114
115
116
117
  t = validity_time;
}

//------------------------------------------------------------------------------
boost::posix_time::ptime nrf_subscription::get_validity_time() const {
  return validity_time;
}

Rohan's avatar
Rohan committed
118
119
120
121
122
123
//------------------------------------------------------------------------------
void nrf_subscription::set_http_version(const uint8_t& httpVersion) {
  http_version = httpVersion;
}

//------------------------------------------------------------------------------
124
uint8_t nrf_subscription::get_http_version() const {
Rohan's avatar
Rohan committed
125
126
127
  return http_version;
}

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
128
129
//------------------------------------------------------------------------------
void nrf_subscription::display() {
130
  Logger::nrf_app().debug("Subscription information");
131
  Logger::nrf_app().debug("\tSub ID: %s", subscription_id.c_str());
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
132

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
133
134
135
136
  Logger::nrf_app().debug(
      "\tNotification URI: %s", nf_status_notification_uri.c_str());
  Logger::nrf_app().debug(
      "\tSubscription condition: %s", sub_condition.to_string().c_str());
137
138

  std::string notif_events_str = {};
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
139
140
141
  for (auto n : notif_events) {
    notif_events_str.append(notification_event_type_e2str[n]);
    notif_events_str.append(", ");
142
  }
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
143
144
  Logger::nrf_app().debug(
      "\tNotification Events: %s", notif_events_str.c_str());
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
145
146
147
  Logger::nrf_app().debug(
      "\tValidity time: %s",
      boost::posix_time::to_iso_string(validity_time).c_str());
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
148
149
150
}

//------------------------------------------------------------------------------
151
void nrf_subscription::subscribe_nf_status_registered() {
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
152
  Logger::nrf_app().debug("Subscribe to NF status change event");
153
154
  ev_connection =
      m_event_sub.subscribe_nf_status_change(  // TODO: To be updated
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
155
156
          boost::bind(
              &nrf_subscription::handle_nf_status_registered, this, _1));
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
157
158
159
}

//------------------------------------------------------------------------------
160
void nrf_subscription::handle_nf_status_registered(
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
161
    const std::shared_ptr<nrf_profile>& profile) {
162
163
164
  std::string nf_instance_id;
  profile.get()->get_nf_instance_id(nf_instance_id);
  Logger::nrf_app().info(
165
      "Handle NF status registered (subscription ID %s), profile ID %s",
166
167
      subscription_id.c_str(), nf_instance_id.c_str());
  // TODO:
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
168
169
  nlohmann::json notification_data   = {};
  notification_data["event"]         = "NF_REGISTERED";
170
  notification_data["nfInstanceUri"] = "";
171
172
173
  // get NF profile based on profile_id
  // NFStatusNotify
  // curl...
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
174
}