Skip to content

Commit

Permalink
added slice_manager + few small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
maiconkist committed Apr 4, 2019
1 parent 13b2dfa commit 712ebbd
Show file tree
Hide file tree
Showing 11 changed files with 383 additions and 116 deletions.
113 changes: 113 additions & 0 deletions app/slice_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#!/usr//bin/env python2

import sys, time

import hydra
import xmlrpclib
import json



# This class receives a hydra_client, which interacts with the Hydra-Server,
# and a xmlrpclib.ServerProxy, which interacts with the UE side.
# Use the methods to configure both the client and ue at the same time.

class Slice:
def __init__(self, client, ue):
self.client = client
self.ue = ue


def free(self):
self.client.free_resources()

def allocate_tx(self, freq, bandwidth):

# Configure TX freq for slice
spectrum_conf = hydra.rx_configuration(freq, bandwidth, False)
ret = self.client.request_tx_resources( spectrum_conf )

if (ret < 0):
print "Error allocating HYDRA TX resources: freq: %f, bandwidth %f" % (freq, bandwidth)
return -1

# Configure the RX freq for UE (to receive from the slice)
self.ue.set_freqrx(freq)
self.ue.set_vr1offset(0)
self.ue.set_vr2offset(0)
self.ue.set_samp_rate(bandwidth)

if (self.ue.get_freqrx() != freq or self.ue.get_samp_rate() != bandwidth):
print "Error allocating UE RX resources: freq: %f, bandwidth %f" % (freq, bandwidth)
return -1

return 0

def allocate_rx(self, freq, bandwidth):
# Configure RX freq for slice
spectrum_conf = hydra.rx_configuration(freq, bandwidth, False)
ret = self.client.request_rx_resources( spectrum_conf )

if (ret < 0):
print "Error allocating TX resources: freq: %f, bandwidth %f" % (freq, bandwidth)

# Configure the RX freq for UE (to receive from the slice)
self.ue.set_freqtx(freq)
self.ue.set_vr1offset(0)
self.ue.set_vr2offset(0)
self.ue.set_samp_rate(bandwidth)

if (self.ue.get_freqtx() != freq or self.ue.get_samp_rate() != bandwidth):
print "Error allocating UE TX resources: freq: %f, bandwidth %f" % (freq, bandwidth)
return -1

return 0


def main():
## IMPORTANT: The script ansible_hydra_client_2tx_2rx already allocated resources for transmission and reception
## These resources are under the use of clients ID 1 and ID 2. The trick of this script is to connect
# with the server using the same ID (1 and 2), and them releasing the resources allocated.
# We can then allocate new resources from this python without impacting the slices.

client1 = hydra.hydra_client("192.168.5.70", 5000, 1, True)


ue1 = xmlrpclib.ServerProxy("http://192.168.5.78:8080")

if client1.check_connection(3) == "":
print("client1 could not connect to server")
sys.exit(1)

# put both the client and the ue in a slice class.
slice1 = Slice( client1, ue1)
# This configuration is just to "clear" the offsets in the gnuradio file.
# Dont remove it.
slice1.allocate_tx(2.43e9 - 300e3, 400e3)
slice1.allocate_rx(2.43e9 + 3e6 - 300e3, 400e3)


if (False):
client2 = hydra.hydra_client("192.168.5.81", 5000, 2)
ue2 = xmlrpclib.ServerProxy("http://192.168.5.81:8080")

if client2.check_connection(3) == "":
print("client2 could not connect to server")
sys.exit(1)
slice2 = Slice( client2, ue2)
slice2.allocate_tx(2.43e9 + 400e3, 200e3)
slice2.allocate_rx(2.43e9 + 3e6 + 300e3, 200e3)


## YOUR CODE HERE



print("Press CTRL-C to quit")
while True:
time.sleep(1)



if __name__ == "__main__":
main()
50 changes: 25 additions & 25 deletions grc_blocks/app/ansible_hydra_gr_client_2tx_2rx.grc
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
</param>
<param>
<key>value</key>
<value>0.01</value>
<value>0.04</value>
</param>
<param>
<key>_enabled</key>
Expand Down Expand Up @@ -247,7 +247,7 @@
</param>
<param>
<key>value</key>
<value>192.168.5.73</value>
<value>192.168.5.70</value>
</param>
</block>
<block>
Expand All @@ -274,7 +274,7 @@
</param>
<param>
<key>_coordinate</key>
<value>(832, 300)</value>
<value>(832, 308)</value>
</param>
<param>
<key>_rotation</key>
Expand Down Expand Up @@ -325,7 +325,7 @@
</param>
<param>
<key>_coordinate</key>
<value>(776, 832)</value>
<value>(768, 828)</value>
</param>
<param>
<key>_rotation</key>
Expand Down Expand Up @@ -372,7 +372,7 @@
</param>
<param>
<key>_coordinate</key>
<value>(320, 300)</value>
<value>(304, 308)</value>
</param>
<param>
<key>_rotation</key>
Expand Down Expand Up @@ -470,7 +470,7 @@
</param>
<param>
<key>_coordinate</key>
<value>(360, 608)</value>
<value>(360, 564)</value>
</param>
<param>
<key>_rotation</key>
Expand Down Expand Up @@ -525,7 +525,7 @@
</param>
<param>
<key>_coordinate</key>
<value>(288, 1152)</value>
<value>(288, 1108)</value>
</param>
<param>
<key>_rotation</key>
Expand Down Expand Up @@ -576,7 +576,7 @@
</param>
<param>
<key>_coordinate</key>
<value>(304, 552)</value>
<value>(304, 508)</value>
</param>
<param>
<key>_rotation</key>
Expand Down Expand Up @@ -623,7 +623,7 @@
</param>
<param>
<key>_coordinate</key>
<value>(256, 1096)</value>
<value>(256, 1052)</value>
</param>
<param>
<key>_rotation</key>
Expand Down Expand Up @@ -674,7 +674,7 @@
</param>
<param>
<key>_coordinate</key>
<value>(36, 352)</value>
<value>(68, 360)</value>
</param>
<param>
<key>_rotation</key>
Expand All @@ -690,7 +690,7 @@
</param>
<param>
<key>mtu</key>
<value>10000</value>
<value>200</value>
</param>
<param>
<key>maxoutbuf</key>
Expand Down Expand Up @@ -741,7 +741,7 @@
</param>
<param>
<key>mtu</key>
<value>10000</value>
<value>200</value>
</param>
<param>
<key>maxoutbuf</key>
Expand Down Expand Up @@ -780,7 +780,7 @@
</param>
<param>
<key>_coordinate</key>
<value>(664, 512)</value>
<value>(664, 468)</value>
</param>
<param>
<key>_rotation</key>
Expand Down Expand Up @@ -867,7 +867,7 @@
</param>
<param>
<key>_coordinate</key>
<value>(528, 1056)</value>
<value>(528, 1012)</value>
</param>
<param>
<key>_rotation</key>
Expand Down Expand Up @@ -954,7 +954,7 @@
</param>
<param>
<key>_coordinate</key>
<value>(576, 252)</value>
<value>(576, 260)</value>
</param>
<param>
<key>_rotation</key>
Expand Down Expand Up @@ -1148,7 +1148,7 @@
</param>
<param>
<key>value</key>
<value>2.22e9+3e6</value>
<value>2.43e9+3e6</value>
</param>
</block>
<block>
Expand Down Expand Up @@ -1191,7 +1191,7 @@
</param>
<param>
<key>value</key>
<value>2.22e9</value>
<value>2.43e9</value>
</param>
</block>
<block>
Expand Down Expand Up @@ -1222,7 +1222,7 @@
</param>
<param>
<key>_coordinate</key>
<value>(992, 512)</value>
<value>(992, 468)</value>
</param>
<param>
<key>_rotation</key>
Expand Down Expand Up @@ -1285,7 +1285,7 @@
</param>
<param>
<key>_coordinate</key>
<value>(848, 1056)</value>
<value>(848, 1012)</value>
</param>
<param>
<key>_rotation</key>
Expand Down Expand Up @@ -1348,7 +1348,7 @@
</param>
<param>
<key>_coordinate</key>
<value>(1024, 264)</value>
<value>(1024, 268)</value>
</param>
<param>
<key>_rotation</key>
Expand Down Expand Up @@ -1403,7 +1403,7 @@
</param>
<param>
<key>_coordinate</key>
<value>(960, 788)</value>
<value>(952, 788)</value>
</param>
<param>
<key>_rotation</key>
Expand Down Expand Up @@ -1470,7 +1470,7 @@
</param>
<param>
<key>value</key>
<value>0.01</value>
<value>0.04</value>
</param>
</block>
<block>
Expand All @@ -1489,7 +1489,7 @@
</param>
<param>
<key>_coordinate</key>
<value>(952, 128)</value>
<value>(952, 100)</value>
</param>
<param>
<key>_rotation</key>
Expand All @@ -1513,7 +1513,7 @@
</param>
<param>
<key>value</key>
<value>0.03</value>
<value>0.04</value>
</param>
</block>
<block>
Expand Down Expand Up @@ -1642,7 +1642,7 @@
</param>
<param>
<key>value</key>
<value>700e3</value>
<value>200e3</value>
</param>
</block>
<connection>
Expand Down
10 changes: 5 additions & 5 deletions grc_blocks/app/ansible_hydra_gr_client_2tx_2rx.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
##################################################
# GNU Radio Python Flow Graph
# Title: Ansible Hydra Gr Client 2Tx 2Rx
# Generated: Wed Mar 13 03:03:11 2019
# Generated: Wed Apr 3 17:57:53 2019
##################################################


Expand All @@ -20,7 +20,7 @@

class ansible_hydra_gr_client_2tx_2rx(gr.top_block):

def __init__(self, ansibleIP='192.168.5.73', freqrx=2.22e9+3e6, freqtx=2.22e9, mul=0.01, mul2=0.03, samp_rate=200e3, vr1offset=-300e3, vr2offset=700e3):
def __init__(self, ansibleIP='192.168.5.70', freqrx=2.43e9+3e6, freqtx=2.43e9, mul=0.04, mul2=0.04, samp_rate=200e3, vr1offset=-300e3, vr2offset=200e3):
gr.top_block.__init__(self, "Ansible Hydra Gr Client 2Tx 2Rx")

##################################################
Expand Down Expand Up @@ -84,8 +84,8 @@ def __init__(self, ansibleIP='192.168.5.73', freqrx=2.22e9+3e6, freqtx=2.22e9, m
debug_log=False,
scramble_bits=False
)
self.blocks_tuntap_pdu_1_0 = blocks.tuntap_pdu('tap1', 10000, False)
self.blocks_tuntap_pdu_1 = blocks.tuntap_pdu('tap0', 10000, False)
self.blocks_tuntap_pdu_1_0 = blocks.tuntap_pdu('tap1', 200, False)
self.blocks_tuntap_pdu_1 = blocks.tuntap_pdu('tap0', 200, False)
self.blocks_tagged_stream_to_pdu_0_0 = blocks.tagged_stream_to_pdu(blocks.byte_t, "len")
self.blocks_tagged_stream_to_pdu_0 = blocks.tagged_stream_to_pdu(blocks.byte_t, "len")
self.blocks_tag_debug_0_0 = blocks.tag_debug(gr.sizeof_char*1, 'VR2 RX', ""); self.blocks_tag_debug_0_0.set_display(True)
Expand Down Expand Up @@ -169,7 +169,7 @@ def set_vr2offset(self, vr2offset):
def argument_parser():
parser = OptionParser(usage="%prog: [options]", option_class=eng_option)
parser.add_option(
"", "--ansibleIP", dest="ansibleIP", type="string", default='192.168.5.73',
"", "--ansibleIP", dest="ansibleIP", type="string", default='192.168.5.70',
help="Set ansibleIP [default=%default]")
return parser

Expand Down
Loading

0 comments on commit 712ebbd

Please sign in to comment.