1 # -------------------------------------------------------------------------------
2 # Copyright (c) 2018-2019 AT&T Intellectual Property.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 # -------------------------------------------------------------------------------
23 import sgnb_reconfiguration_complete_pb2
24 import ue_context_release_pb2
25 import x2ap_streaming_pb2
28 # --------------------------------
35 conn_flnm = "MT_000010280"
36 dis_flnm = "MT_000010050"
38 fifo_dir = "/tmp/mcl/fifos"
40 # -------------------------------
43 def process_conn_record(ofl,gnb_id, ue_id, ts):
44 # print "Connected ue_iud="+str(ue_id)+", gnb_id="+str(gnb_id)
45 X2APStreaming = x2ap_streaming_pb2.X2APStreaming() # header message
46 X2APStreaming.header.gNbID.value = "Bar"
49 utc_time = datetime.datetime.utcfromtimestamp(sec)
50 diff = utc_time - datetime.datetime(1900, 1, 1, 0, 0, 0)
51 ntp_hi = diff.days*24*60*60+diff.seconds
52 ntp_lo = (ms << 32) / 1000
53 X2APStreaming.header.timestamp = ntp_hi << 32 | ntp_lo
55 # root = sgnb_reconfiguration_complete_pb2.SgNBReconfigurationComplete()
56 root = X2APStreaming.sgNBReconfigurationComplete
58 root.id_MeNB_UE_X2AP_ID = ue_id
59 root.id_SgNB_UE_X2AP_ID = gnb_id
60 child = root.id_ResponseInformationSgNBReconfComp
61 child.success_SgNBReconfComp.meNBtoSgNBContainer.value = "foo"
63 v = X2APStreaming.SerializeToString()
66 ofl.write("{0:7}".format(vlen))
76 def process_dis_record(ofl, gnb_id, old_enb_id, new_enb_id, ts):
77 # print "Disconnected old_ue_iud="+str(old_enb_id)+", gnb_id="+str(gnb_id)+", new_ue_id="+str(new_enb_id)
78 X2APStreaming = x2ap_streaming_pb2.X2APStreaming() # header message
79 X2APStreaming.header.gNbID.value = "Bar"
82 utc_time = datetime.datetime.utcfromtimestamp(sec)
83 diff = utc_time - datetime.datetime(1900, 1, 1, 0, 0, 0)
84 ntp_hi = diff.days*24*60*60+diff.seconds
85 ntp_lo = (ms << 32) / 1000
86 X2APStreaming.header.timestamp = ntp_hi << 32 | ntp_lo
88 # root = ue_context_release_pb2.UEContextRelease()
89 root = X2APStreaming.ueContextRelease
91 root.id_Old_eNB_UE_X2AP_ID = old_enb_id
92 root.id_New_eNB_UE_X2AP_ID = new_enb_id
93 root.id_SgNB_UE_X2AP_ID.value = gnb_id
95 v = X2APStreaming.SerializeToString()
98 ofl.write("{0:7}".format(vlen))
106 # -------------------------------
107 # main body of data generator
109 enb_to_ue = {} # avoid duplicate enb_ue_ids
110 gnb_to_ue = {} # avoid duplicate gnb_ue_ids
114 for i in xrange(0,n_ue):
115 enb_id = random.randint(1,ue_id_range)
116 while enb_id in enb_to_ue:
117 enb_id = random.randint(1,ue_id_range)
118 ue_list.append({"state": "dis", "enb_id": enb_id})
119 enb_to_ue[enb_id] = i
121 if not os.path.exists(fifo_dir + "/" + conn_flnm):
122 os.mkfifo(fifo_dir + "/" + conn_flnm)
124 if not os.path.exists(fifo_dir + "/" + dis_flnm):
125 os.mkfifo(fifo_dir + "/" + dis_flnm)
127 cfl = open(fifo_dir + "/" + conn_flnm,"w", 0)
128 dfl = open(fifo_dir + "/" + dis_flnm, "w", 0)
134 curr_time = int(time.time())
137 for i in xrange(0, events_per_fl):
138 ueix = random.randint(0,n_ue-1)
139 if ueix in processed:
140 ueix = random.randint(0,n_ue-1)
141 processed.append(ueix)
143 curr_ue = ue_list[ueix]
144 if curr_ue["state"] == "dis":
145 gnb_id = random.randint(1,ue_id_range)
146 while gnb_id in gnb_to_ue:
147 gnb_id = random.randint(1,ue_id_range)
148 gnb_to_ue[gnb_id] = ueix
149 curr_ue["gnb_id"] = gnb_id
150 curr_ue["state"] = "conn"
151 process_conn_record(cfl,curr_ue["gnb_id"], curr_ue["enb_id"],1000*curr_time +50*i)
153 new_enb_id = random.randint(1,ue_id_range)
154 while new_enb_id in enb_to_ue:
155 new_enb_id = random.randint(1,ue_id_range)
156 old_enb_id = curr_ue["enb_id"]
157 gnb_id = curr_ue["gnb_id"]
158 del enb_to_ue[old_enb_id]
159 del gnb_to_ue[gnb_id]
160 enb_to_ue[new_enb_id] = ueix
162 curr_ue["enb_id"] = new_enb_id
163 curr_ue["state"] = "dis"
164 process_dis_record(dfl,gnb_id, old_enb_id, new_enb_id,1000*curr_time +50*i)
166 time.sleep(epoch_len)