Commit 45c07964 authored by wangdong's avatar wangdong

ls

parent ff51437c
import torch
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
import random
import gym
from collections import deque
from maze_env import Maze
from slicing import SliceEnv
use_gpu = torch.cuda.is_available()
class replay_buffer(object):
def __init__(self, capacity):
self.capacity = capacity
self.memory = deque(maxlen=self.capacity)
def store(self, observation, action, reward, next_observation, done):
observation = np.expand_dims(observation, 0)
next_observation = np.expand_dims(next_observation, 0)
self.memory.append([observation, action, reward, next_observation, done])
def sample(self, batch_size):
batch = random.sample(self.memory, batch_size)
observation, action, reward, next_observation, done = zip(* batch)
return np.concatenate(observation, 0), action, reward, np.concatenate(next_observation, 0), done
def __len__(self):
return len(self.memory)
class dueling_ddqn(nn.Module):
def __init__(self, observation_dim, action_dim):
super(dueling_ddqn, self).__init__()
self.observation_dim = observation_dim
self.action_dim = action_dim
self.fc = nn.Linear(self.observation_dim, 32)
self.adv_fc1 = nn.Linear(32, 32)
self.adv_fc2 = nn.Linear(32, self.action_dim)
self.value_fc1 = nn.Linear(32, 32)
self.value_fc2 = nn.Linear(32, 1)
def forward(self, observation):
feature = self.fc(observation)
advantage = self.adv_fc2(F.relu(self.adv_fc1(F.relu(feature))))
value = self.value_fc2(F.relu(self.value_fc1(F.relu(feature))))
return advantage + value - advantage.mean()
def act(self, observation, epsilon):
if random.random() > epsilon:
q_value = self.forward(observation)
action = q_value.max(1)[1].data[0].item()
else:
action = random.choice(list(range(self.action_dim)))
return action
def train(buffer, target_model, eval_model, gamma, optimizer, batch_size, loss_fn, count, soft_update_freq):
observation, action, reward, next_observation, done = buffer.sample(batch_size)
observation = torch.FloatTensor(observation).cuda()
action = torch.LongTensor(action).cuda()
reward = torch.FloatTensor(reward).cuda()
next_observation = torch.FloatTensor(next_observation).cuda()
done = torch.FloatTensor(done).cuda()
q_values = eval_model.forward(observation)
next_q_values = target_model.forward(next_observation)
argmax_actions = eval_model.forward(next_observation).max(1)[1].detach()
next_q_value = next_q_values.gather(1, argmax_actions.unsqueeze(1)).squeeze(1)
q_value = q_values.gather(1, action.unsqueeze(1)).squeeze(1)
expected_q_value = reward + gamma * (1 - done) * next_q_value
loss = loss_fn(q_value, expected_q_value.detach())
optimizer.zero_grad()
loss.backward()
optimizer.step()
if count % soft_update_freq == 0:
target_model.load_state_dict(eval_model.state_dict())
if __name__ == '__main__':
gamma = 0.99
learning_rate = 1e-3
batch_size = 64
soft_update_freq = 100
capacity = 10000
exploration = 100
epsilon_init = 0.9
epsilon_min = 0.05
decay = 0.99
episode = 1000000
render = True
env = SliceEnv()
observation_dim = env.observation_space.shape[0]
action_dim = env.action_space.n
target_net = dueling_ddqn(observation_dim, action_dim).cuda()
eval_net = dueling_ddqn(observation_dim, action_dim).cuda()
eval_net.load_state_dict(target_net.state_dict())
optimizer = torch.optim.Adam(eval_net.parameters(), lr=learning_rate)
buffer = replay_buffer(capacity)
loss_fn = nn.MSELoss().cuda()
epsilon = epsilon_init
count = 0
weight_reward = None
for i in range(episode):
obs = env.reset()
if epsilon > epsilon_min:
epsilon = epsilon * decay
reward_total = 0
if render:
env.render()
while True:
action = eval_net.act(torch.FloatTensor(np.expand_dims(obs, 0)).cuda(), epsilon)
count += 1
next_obs, reward, done = env.step(action)
buffer.store(obs, action, reward, next_obs, done)
reward_total += reward
obs = next_obs
if render:
env.render()
if i > exploration:
train(buffer, target_net, eval_net, gamma, optimizer, batch_size, loss_fn, count, soft_update_freq)
if done or count%1==0:
if not weight_reward:
weight_reward = reward_total
else:
weight_reward = 0.99 * weight_reward + 0.01 * reward_total
print('episode: {} epsilon: {:.2f} reward: {} weight_reward: {:.3f}'.format(i+1, epsilon, reward_total, weight_reward))
break
......@@ -24,44 +24,78 @@ const template = [
label: '查看',
submenu: [
{
label: 'FlexRAN Drone® Mosaic5G ',
label: 'AI-Engine Jupyter Lab ',
click() {
openFlexran()
},
},
{
label: 'AI-Engine Code-Server ',
click: async () => {
const { shell } = require('electron')
await shell.openExternal('https://code.ustb-oai.com:8889')
}
},
]
},
// {
// label: '远程连接',
// submenu: [
// {
// label: 'OAI核心网',
// click() {
// createNewWindow("192.168.1.12")
// },
// },
// {
// label: 'OAI基站',
// click() {
// createNewWindow("192.168.1.193")
// },
// },
// {
// label: 'OAI-SIM',
// click() {
// createNewWindow("192.168.1.212")
// },
// },
// {
// label: 'AI-Engine',
// click() {
// createNewWindow("192.168.1.150",'tony','199710')
// },
// },
// ]
// },
{
label: '远程连接',
label: '编辑',
submenu: [
{
label: 'OAI核心网',
click() {
createNewWindow("192.168.1.12")
},
},
{
label: 'OAI基站',
click() {
createNewWindow("192.168.1.193")
},
},
{
label: 'OAI-SIM',
click() {
createNewWindow("192.168.1.212")
},
},
{
label: 'AI-Engine',
click() {
createNewWindow("192.168.1.150",'tony','199710')
},
},
{ role: 'undo' },
{ role: 'redo' },
{ type: 'separator' },
{ role: 'cut' },
{ role: 'copy' },
{ role: 'paste' },
...(isMac ? [
{ role: 'pasteAndMatchStyle' },
{ role: 'delete' },
{ role: 'selectAll' },
{ type: 'separator' },
{
label: 'Speech',
submenu: [
{ role: 'startSpeaking' },
{ role: 'stopSpeaking' }
]
}
] : [
{ role: 'delete' },
{ type: 'separator' },
{ role: 'selectAll' }
])
]
},
{
......@@ -73,12 +107,20 @@ const template = [
runeNB()
},
},
{ type: 'separator' },
{
label: '运行OAI基站(L2-nFAPI)',
click() {
runeNBl2()
},
}
label: 'OAI基站(L2-nFAPI)',
submenu: [
{ label: '启动OAI基站',
click() {
addUE()
},
},
]
},
]
},
......@@ -116,9 +158,12 @@ function runeNB(){
function runeNBl2(){
mainWindow.webContents.send('eNBl2', '/page1');
}
function addUE(){
mainWindow.webContents.send('addUE', '/page1');
}
function createNewWindow(host,user,pass){
function createNewWindow(suburl){
let win
/**
* Initial window options
......@@ -135,8 +180,10 @@ function createNewWindow(host,user,pass){
webSecurity: false
}
})
win.loadURL(winURL+`/#/ssh/${host}/start_enb/${user==undefined?'root':user}/${pass==undefined?'199710':pass}/`)
//win.loadURL(winURL+`/#/prb/`)
// win.loadURL(winURL+`/#/ssh/${host}/start_enb/${user==undefined?'root':user}/${pass==undefined?'199710':pass}/`)
win.loadURL(`http://code.ustb-oai.com:2222/ssh/host/${host}?autologin=1&user=${user==undefined?'root':user}&pass=${pass==undefined?'199710':pass}`)
//+`/#/ssh/${host}/start_enb/${user==undefined?'root':user}/${pass==undefined?'199710':pass}/`
newWindows.push(win)
}
......@@ -148,8 +195,8 @@ Menu.setApplicationMenu( Menu.buildFromTemplate(template));
* Initial window options
*/
mainWindow = new BrowserWindow({
minWidth:1920,
minHeight:1000,
minWidth:920,
minHeight:500,
width: screen.getPrimaryDisplay().workAreaSize.width,
height: screen.getPrimaryDisplay().workAreaSize.height,
useContentSize: true,
......@@ -165,22 +212,24 @@ Menu.setApplicationMenu( Menu.buildFromTemplate(template));
mainWindow = null
})
}
function openFlexran(){
child = new BrowserWindow({
minWidth:500,
minHeight:500,
width: 500,
height: 500,
parent:mainWindow,
useContentSize: true,
webPreferences: {
nodeIntegration: true,
webSecurity: false
}
})
console.log(winURL)
child.loadURL(`http://${url}:2224`)
}
let openFlexran=async() =>{
// child = new BrowserWindow({
// minWidth:500,
// minHeight:500,
// width: 900,
// height: 600,
// parent:mainWindow,
// useContentSize: true,
// webPreferences: {
// nodeIntegration: true,
// webSecurity: false
// }
// })
// console.log(winURL)
// child.loadURL(`http://${url}:8888`)
await shell.openExternal(`http://${url}:8888/lab/tree/dqn_zoo`)
};
......@@ -210,7 +259,7 @@ app.on('resize', (e, cmd) => {
})
ipcMain.on('change-url', function(event, arg) {
console.log(arg); // prints "ping"
console.log("ssss"); // prints "ping"
url = arg
event.returnValue = 'pong';
});
......
......@@ -38,23 +38,20 @@ export default {
"ssh-page": SshPage,
},
async mounted() {
console.log(this.$store);
let res = await flexranAPI.DETECT({});
try {
let returnCitySN = JSON.parse(res.split("= ")[1].split(";")[0]);
let local = await flexranAPI.DETECT_LOCAL({}, returnCitySN["cip"]);
if (local.area == "北京科技大学") {
console.log("在校园网内");
ipcRenderer.sendSync("change-url", "10.25.20.227");
ipcRenderer.sendSync("change-url", "code.ustb-oai.com");
flexranAPI.SET_URL({});
} else {
console.log("不在校园网");
}
} catch (error) {
console.log("在校园网内");
ipcRenderer.sendSync("change-url", "10.25.20.227");
ipcRenderer.sendSync("change-url", "code.ustb-oai.com");
flexranAPI.SET_URL({});
}
......
<template>
<div style="height:100%">
<iframe id="show-iframe" style="height:500px;width:100%" frameborder=0 name="showHere" scrolling=auto :src="src"></iframe>
<!-- <img src="~@/assets/ustb-oai.com.png" alt="electron-vue" height="4%" > -->
<div style="height: 100%">
<div
v-for="(item1, index1) in srcs"
:key="index1"
v-bind="item1"
v-show="item1.active">
<iframe
:id="index1"
style="height: 500px; width: 100%"
frameborder="0"
:name="index1"
scrolling="auto"
:src="item1.url"
></iframe>
</div>
<div class="flex" >
<div
v-for="(item1, index1) in srcs"
:key="index1"
v-bind="item1"
@click="handleCommand1(index1)"
:class="item1.active?'activate':'s'"
class="tags"
>
<el-dropdown >
<el-tag v-if="item1.name=='FlexRan'" :type="item1.active?'success':'info'">
{{ item1.name }}
</el-tag>
<el-tag v-else closable @close="handleClose(index1)" :type="item1.active?'success':'info'" >
{{ item1.name }}
</el-tag>
<el-dropdown-menu slot="dropdown" >
<el-dropdown-item ><div v-if="item1.name=='OAI_ENB'" @click="handleCommand2(index1,0)"> 查看OAI基站LOG</div></el-dropdown-item>
<el-dropdown-item ><div v-if="item1.name=='OAI_ENB'" @click="handleCommand2(index1,3)"> 查看OAI UELOG</div></el-dropdown-item>
<el-dropdown-item ><div v-if="item1.name=='FlexRan'" @click="refresh"> 刷新</div></el-dropdown-item>
<el-dropdown-item ><div v-if="item1.name=='AI-Engine'" @click="handleCommand2(index1,1)"> 启动DRL切片智能分配</div></el-dropdown-item>
<el-dropdown-item ><div v-if="item1.name=='CoreNet'" @click="handleCommand2(index1,2)"> 查看MME LOG</div></el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</div>
<el-dropdown @command="handleCommand">
<el-tag type="primary">
NewSSH<i class="el-icon-plus el-icon--right"></i>
</el-tag>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item command="0">OAI_ENB</el-dropdown-item>
<el-dropdown-item command="1">OAI_UE</el-dropdown-item>
<el-dropdown-item command="2">AI-Engine</el-dropdown-item>
<el-dropdown-item command="3">CoreNet</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</div>
<!-- <img src="~@/assets/ustb-oai.com.png" alt="electron-vue" height="4%" > -->
</div>
</template>
......@@ -9,54 +62,129 @@
import Vue from "vue";
import vueJsonTreeView from "vue-json-tree-view";
import * as flexranAPI from "../../../utils/flexranAPI";
import _ from 'lodash'
Vue.use(vueJsonTreeView);
export default {
data() {
return {
dataList:[],
host:'',
action:'',
src:'http://10.25.20.227:2224'
dataList: [],
host: "",
action: "",
view: true,
commands:['tail -f ~/log/enb.log','cd /root/dqn_zoo/Dueling\\ DDQN/ && python dueling_ddqn.py','tail -f /root/log/mme.log','tail -f ~/log/ue.log'],
ssh_srcs:[ {
name: "OAI_ENB",
active: false,
url:
"http://10.25.20.227:2222/ssh/host/192.168.1.193?autologin=1&user=root&pass=199710",
},
{
name: "OAI_UE",
active: false,
url:
"https://10.25.20.227:2222/ssh/host/192.168.1.36?autologin=1&user=root&pass=199710",
},
{
name: "AI-Engine",
active: false,
url:
"http://10.25.20.227:2222/ssh/host/192.168.1.80?autologin=1&user=root&pass=199710",
},
{
name: "CoreNet",
active: false,
url:
"http://10.25.20.227:2222/ssh/host/192.168.1.12?autologin=1&user=root&pass=199710",
},],
srcs: [
{ name: "FlexRan", active: true, url: "http://10.25.20.227:2224" },
],
menus: [
{ name: "FlexRan", active: true },
{ name: "OAI_ENB", active: true },
{ name: "OAI_UE", active: true },
{ name: "AI-Engine", active: true },
{ name: "CoreNet", active: true },
],
};
},
async mounted() {
this.host=this.$route.params.host
this.action=this.$route.params.action
this.user=this.$route.params.user
this.pass=this.$route.params.pass
let res = await flexranAPI.DETECT({})
try {
let returnCitySN = JSON.parse(res.split("= ")[1].split(";")[0])
let local = await flexranAPI.DETECT_LOCAL({},returnCitySN['cip'])
if(local.area=="北京科技大学"){
this.src=`http://10.25.20.227:2224`
}
else{
this.src=`http://ustb-oai.com:2224`
}
} catch (error) {
this.src=`http://10.25.20.227:2224`
this.host = this.$route.params.host;
this.action = this.$route.params.action;
this.user = this.$route.params.user;
this.pass = this.$route.params.pass;
let res = await flexranAPI.DETECT({});
try {
let returnCitySN = JSON.parse(res.split("= ")[1].split(";")[0]);
let local = await flexranAPI.DETECT_LOCAL({}, returnCitySN["cip"]);
if (local.area == "北京科技大学") {
this.src = `http://10.25.20.227:2224`;
} else {
this.src = `http://ustb-oai.com:2224`;
}
} catch (error) {
this.src = `http://10.25.20.227:2224`;
}
},
methods: {
getJS(id,str) {
var child = document
.getElementById(String(id))
.contentWindow.socket.emit("control", str);
},
refresh() {
location.reload()
},
handleCommand(command) {
this.$message("NewSSH to " + this.ssh_srcs[Number(command)].url.split('?')[0]);
this.srcs.push( _.cloneDeep(this.ssh_srcs[Number(command)]))
this.handleCommand1(this.srcs.length-1)
},
handleCommand2(id,command) {
this.getJS(id,this.commands[command])
},
handleCommand1(command) {
for(let i =0;i<this.srcs.length;i++){
if(i==command){
this.srcs[i].active=true
}
else{
this.srcs[i].active=false
},
methods:{
getJS (){
var child = document.getElementById("show-iframe").contentWindow;
let a= child.document.getElementById("menu");
console.log(a)
}
}
},
handleClose(index){
_.pullAt(this.srcs, index)
this.handleCommand1(index-1)
}
},
};
</script>
<style>
html,body,#app{
height: 100%;
html,
body,
#app {
height: 100%;
}
.flex {
display: flex;
width: 100%;
margin-right: 10px;
padding-right: 10px;
}
.tags{
margin-right: 1px;
}
#icon {
position: fixed;
margin-top: 470px;
margin-left: 10px;
z-index: 9999;
}
.activate{
background-color: #aaa;
}
.left{}
</style>
<template>
<div>
<el-card>
<el-table :data="dataList" border stripe>
<el-table :data="littleDate" border stripe>
<el-table-column type="index" label="UE"></el-table-column>
<el-table-column prop="rnti" label="RNTI" width="100">
</el-table-column>
......@@ -48,7 +48,18 @@
</el-table-column>
<el-table-column prop="imsi" label="IMSI"> </el-table-column>
</el-table>
<el-pagination
layout="prev, pager, next"
:total="dataList.length"
style="margin-top:5px"
:page-size="4"
background
@current-change="handleCurrentChange"
:current-page="currentPage"
>
</el-pagination>
</el-card>
</div>
</template>
<script>
......@@ -58,7 +69,9 @@ import * as flexranAPI from "../../../utils/flexranAPI";
export default {
data() {
return {
currentPage:1,
hover: false,
littleDate:[],
pingInfo:
"PING 172.16.0.x (172.16.0.x) 56(84) bytes of data.<br/>64 bytes from 172.16.0.6: icmp_seq=1 ttl=64 time=39.5 ms<br/>64 bytes from 172.16.0.6: icmp_seq=2 ttl=64 time=39.1 ms<br/>64 bytes from 172.16.0.6: icmp_seq=3 ttl=64 time=28.7 ms<br/>64 bytes from 172.16.0.6: icmp_seq=4 ttl=64 time=45.6 ms<br/><br/>--- 172.16.0.6 ping statistics ---<br/>4 packets transmitted, 4 received, 0% packet loss, time 242ms<br/>rtt min/avg/max/mdev = 28.799/38.307/45.687/6.068 ms<br/>",
};
......@@ -87,8 +100,24 @@ export default {
},
deep: true,
},
dataList: {
handler(newValue, oldValue) {
this.littleDate=newValue.slice((this.currentPage-1)*4,(this.currentPage-1)*4+4)
},
deep: true,
},
},
mounted(){
this.littleDate=this.dataList.slice(0*4,+4)
},
methods: {
handleCurrentChange(val){
console.log(val)
this.currentPage=val
val=val-1
console.log(this.currentPage)
this.littleDate=this.dataList.slice(val*4,val*4+4)
},
async getping(imsi) {
this.timer = setInterval(() => {
flexranAPI.SEND_PING({ imsi: imsi }).then((result) => {
......
......@@ -16,7 +16,7 @@
</template>
</el-table-column>
<el-table-column prop="label" label="切片类型" width="100">
<el-table-column prop="label" label="业务类型" width="100">
</el-table-column>
<el-table-column label="吞吐量(Mps)">
<template slot-scope="scope">
......@@ -30,7 +30,7 @@
</el-table-column>
<el-table-column label="PRB(x2)">
<template slot-scope="scope">
{{ scope.row.ddqn.mrb }}
{{ scope.row.id==0?'*':scope.row.ddqn.mrb }}
</template>
</el-table-column>
<el-table-column label="RB使用情况">
......@@ -128,6 +128,7 @@ export default {
background: "rgba(0, 0, 0, 0.7)",
});
setTimeout(() => {
flexranAPI.ADD_SLICE(a, -1);
loading.close();
this.$message({
message: "成功启动OAI基站",
......@@ -137,6 +138,44 @@ export default {
}
});
ipcRenderer.on("addUE", (event, arg) => {
if (arg) {
this.$prompt('请输入激活UE数目', 'L2-nFAPI', {
confirmButtonText: '确定',
cancelButtonText: '取消',
inputPattern: /^[0-9]$|^[0-2][0-9]$|^3[0-2]$/,
inputErrorMessage: 'MAX_UE=32'
}).then(({ value }) => {
flexranAPI.START_ENB_L2({ues:value});
const loading = this.$loading({
lock: true,
text: "Loading",
spinner: "el-icon-loading",
background: "rgba(0, 0, 0, 0.7)",
});
setTimeout(() => {
loading.close();
this.$message({
message: "成功启动OAI基站",
type: "success",
});
}, 2000);
setTimeout(()=>{
flexranAPI.ADD_SLICE(a, -1);
},4000)
}).catch(() => {
this.$message({
type: 'info',
message: '取消输入'
});
});
// flexranAPI.ADD_UE({ueid:this.$store.state.ue_nums});
// console.log(arg)
// this.$store.commit("addUes", {});
}
});
},
};
</script>
......
......@@ -5,7 +5,11 @@ const mutations = {
updateUes(state, obj) {
return state.ue_list = obj.ue_list;
} ,
addUes(state, obj) {
return state.ue_nums += 1;
} ,
updatePrbs(state, obj) {
obj.prb_info=resize_(obj.prb_info)
if(state.prb_info.length==30){
state.prb_info.shift();
......@@ -14,5 +18,10 @@ const mutations = {
return state.prb_info.push(obj.prb_info);
}
}
const resize_ = (arr)=>{
for(let i=0;i<3;i++){
arr.unshift(arr.pop());
}
return arr
}
export default mutations;
\ No newline at end of file
const state = {
slice_info:[],
ue_list:[],
prb_info:[]
prb_info:[],
ue_nums:0
}
export default state;
\ No newline at end of file
......@@ -42,7 +42,19 @@ export function GET_URL (data = {}) {
// 接口请求
return request({
url: `http://${url}:8110/api/startenbl2`,
method: `get`,
method: `post`,
data
})
}
/**
* @description Add_UE
* @param {Object} data NONE
*/
export function ADD_UE (data = {}) {
// 接口请求
return request({
url: `http://${url}:8110/api/startue`,
method: `post`,
data
})
}
......
......@@ -8439,11 +8439,6 @@ vue-template-es2015-compiler@^1.9.0:
resolved "https://registry.yarnpkg.com/vue-template-es2015-compiler/-/vue-template-es2015-compiler-1.9.1.tgz#1ee3bc9a16ecbf5118be334bb15f9c46f82f5825"
integrity sha512-4gDntzrifFnCEvyoO8PqyJDmguXgVPxKiIxrBKjIowvL9l+N66196+72XVYR8BBf1Uv1Fgt3bGevJ+sEmxfZzw==
vue2-highcharts@^1.2.5:
version "1.2.5"
resolved "https://registry.yarnpkg.com/vue2-highcharts/-/vue2-highcharts-1.2.5.tgz#4ab5ace0573d2e02a0cfd4029e3d7dbba2de2205"
integrity sha512-di7kuqZyqo77pmCs23s+wIyA1aBuKMxRJg871ggcj0Y1GopfF9j/cPlmwgjyIMaOHz4iQmvfn8hEDNOMW7etEQ==
vue@^2.5.16:
version "2.6.12"
resolved "https://registry.yarnpkg.com/vue/-/vue-2.6.12.tgz#f5ebd4fa6bd2869403e29a896aed4904456c9123"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment