Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdface committed Mar 12, 2021
0 parents commit 640a0a7
Show file tree
Hide file tree
Showing 17 changed files with 6,058 additions and 0 deletions.
Binary file added .coverage
Binary file not shown.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PYTHONPATH=${workspaceDir}/lib
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 DingYi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
57 changes: 57 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Changelist
* 1.0.0, first release

# Feedback

give your feedback by following ways<br/>

* visit https://github.com/dvdface/fiberhome-oltcli (preferred)

* send email to dvdface@gmail.com


# How to install

`pip install fiberhome-oltcli`

# Known issues

None <br/>


# Overview

With *fiberhome-oltcli* library, you can easily access olt's commandline interface.<br/>

# How to use

* **Chassis class<br/>**

```
# connect testcenter with ip 10.182.32.138 , without reserving any port
# creating chassis class will auto connect chassis
chassis = Chassis('10.182.32.138')
# disconnect chassis
chassis.disconnect()
# apply changes ( it will apply automatically)
chassis.apply()
# connect testcenter and reserve port
chassis = Chassis('10.182.32.138', [{ 'location' : '//10.182.32.138/1/1', 'vid': None}, { 'location' : '//10.182.32.138/1/2', 'vid': None}])
# connect testcenter, reserve port and specify a default vlan with specified vid
# when you create a device under the port, it will insert a vlan layer with vid 100 for you
# when you create a streamblock, it will insert a vlan layer with vid 100 for you too
chassis = Chassis('10.182.32.138', [{ 'location' : '//10.182.32.138/1/1', 'vid': 100}])
# save xml file
chassis.save('test_configuration.xml')
# get chassis serial number
chassis.serial
# get chassis ip
chassis.ip
```
Empty file added oltcli/__init__.py
Empty file.
2 changes: 2 additions & 0 deletions oltcli/aw/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .olt import *
from .onu import *
148 changes: 148 additions & 0 deletions oltcli/aw/olt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
'''
Action words used to configure olt-related settigns
'''
from typing import NoReturn, Union

from ..utils import dotdict, break_frame_slot_port, validate_type
from ..cli import OLTCLI
from ..cli.common import AuthMode

def add_port_vlan(olt_dev:dotdict, port:str, vid:Union[str, int], strip:bool=False) -> NoReturn:
"""add port vlan in uplink port
Args:
olt_dev (dotdict): olt want to set
port (str): 端口号,形式为frameid/slotid/portid
vid (str or int): VID, 支持1000 - 2000的配置,也支持单个的vid, 如 1000
strip (bool, optional): 是否剥离tag,默认False,不剥离。True,剥离。
"""
validate_type('strip', strip, bool)

cli = OLTCLI.get(olt_dev)
frame, slot, port = break_frame_slot_port(port)
vid = str(vid).replace('-', ' to ')
tag = 'tag' if strip == False else 'untag'

cli.del_port_vlan(vid, slot, port)
cli.set_port_vlan(vid, tag, slot, port)

def del_port_vlan(olt_dev:dotdict, port:str, vid:Union[str, int]) -> NoReturn:
"""删除 VLAN添加端口
Args:
olt_dev (dotdict): 要操作的OLT
port (str): 端口号,形式为frameid/slotid/portid
vid (str or int): VID, 支持1000 - 2000的配置,也支持单个的vid, 如 1000
"""
cli = OLTCLI.get(olt_dev)
frame, slot, port = break_frame_slot_port(port)
vid = str(vid).replace('-', ' to ')

cli.del_port_vlan(vid, slot, port)

def set_igmp_vlan(olt_dev:dotdict, vid:int) -> NoReturn:
"""配置组播VLAN
Args:
olt_dev (dotdict): 要操作的OLT
vid (int): 要配置的组播VLAN
"""
cli = OLTCLI.get(olt_dev)
cli.set_igmp_vlan(vid)

def set_igmp_mode(olt_dev:dotdict, mode:str) -> NoReturn:
"""配置组播模式
Args:
olt_dev (dotdict): 要操作的OLT
mode (str): 要配置的组播模式
"""
cli = OLTCLI.get(olt_dev)
cli.set_igmp_mode(mode)

def add_service_vlan(olt_dev:dotdict, service_name:str, begin_vid:int, end_vid:int, service_type:str) -> NoReturn:
"""配置局端外层VLAN数据
Args:
olt_dev (dotdict): 要操作的OLT
name (str)): 业务VLAN名称
begin_vid (int): 业务起始vid
end_vid (int): 业务结束vid
service_type (str): 业务的类型, 仅限'cnc', 'data', 'iptv', 'ngn', 'system', 'uplinksub', 'vod', 'voip'类型
"""
cli = OLTCLI.get(olt_dev)
cli.set_service_vlan(service_name, '%s - %s' % (begin_vid, end_vid), service_type)

def del_service_vlan(olt_dev:dotdict, service_name:str) -> NoReturn:
"""要删除的局端外层VLAN
Args:
olt_dev (dotdict): 要操作的OLT
service_name (str): 局端外层VLAN名称
"""
cli = OLTCLI.get(olt_dev)
cli.del_service_vlan(service_name)

def add_static_route(olt_dev:dotdict, ip:str, mask:str, hop:str, metric:int=0) -> NoReturn:
"""配置网络层静态路由
Args:
olt_dev (dotdict): 要操作的OLT
ip (str): 目的IP
mask (str): 目的掩码
hop (str): 下一跳
metric (int): 权值
"""
cli = OLTCLI.get(olt_dev)
cli.set_static_route(hop, ip, mask, metric)

def del_static_route(olt_dev:dotdict, ip:str, mask:str, hop:str) -> NoReturn:
"""删除网络层静态路由
Args:
olt_dev (dotdict): 要操作的OLT
ip (str): 目的IP
mask (str): 目的掩码
hop (str): 下一跳
"""
cli = OLTCLI.get(olt_dev)
cli.del_static_route(hop, ip, mask, metric=None)

def set_pon_auth_mode(olt_dev:dotdict, slot:int, port:int, mode:str) -> NoReturn:
"""配置PON口认证模式
Args:
olt_dev (dotdict): 要操作的OLT
slot (int): 槽位号
port (int): 端口号
mode (str or AuthMode): 认证模式
"""
cli = OLTCLI.get(olt_dev)
cli.set_auth_mode(slot, port, AuthMode(mode) if type(mode) == str else mode)


# TODO: 上下行带宽模板

# TODO: QinQ 模板

__all__ = [
# VLAN业务
'add_port_vlan',
'del_port_vlan',

# VLAN业务-局端VLAN
'add_service_vlan',
'del_service_vlan',

# 组播
'set_igmp_vlan',
'set_igmp_mode',

# 以太网基本配置
'add_static_route',
'del_static_route',

# 公共配置
# 公共配置-Pon口
'set_pon_auth_mode'
]
127 changes: 127 additions & 0 deletions oltcli/aw/onu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
'''
配置ONU的Action Word
'''
from typing import NoReturn, Union
from ..utils import validate_type, dotdict
from ..cli import OLTCLI


def clear_port_service(olt_dev:dotdict, onu_dev:dotdict, onu_eth:int) -> NoReturn:
"""删除ONU 端口业务配置
Args:
olt_dev (dotdict): 要操作的OLT
onu_dev (dotdict): 要操作的ONU
onu_eth (int): 要操作的ONU网口号
"""
cli = OLTCLI.get(olt_dev)
cli.set_onu_port_vlan_service_count(onu_dev.sn, onu_eth, 0)

def add_port_service(olt_dev:dotdict, onu_dev:dotdict, onu_eth:int, **kargs) -> NoReturn:
"""ONU 端口业务配置
Args:
olt_dev (dotdict): 要操作的OLT
onu_dev (dotdict): 要操作的ONU
onu_eth (int): 要操作的ONU网口号
tls (bool, optional): 配置TLS,可选。True,使能TLS; False,禁用TLS(默认)
classification (list, optional): 业务区分,默认不区分。
service_type (str, optional): 业务类型。unicast,单播(默认); multicast,多播
cvlan_mode (str, optional): CVLAN模式。transparent,透传(默认);tag,打标签
cvlan_vid (int, optional): CVLAN VID。默认,无
cvlan_cos (int, optional): 优先级,COS。默认,无
cvlan_tpid (int, optional): 标签协议标识。默认,33024
isp_vlan_vid (int, optional): SVLAN VID。默认, 无
isp_vlan_cos (int, optional): SVLAN COS。默认,无
upstream_bandwidth_profile (str, optional): 上行带宽模板。默认, 无
downstream_bandwidth_profile (str, optional): 下行带宽模板。默认, 无
dataservice_bandwidth_type (): 数据业务带宽类型。默认, 系统默认
priority_queue (int, optional): 优先级队列。默认,0
gem_port (int, optional): GEM Port。默认,0
enable_translate (bool, optional): 使能翻译状态。默认,False
translate_vid (int, optional): 翻译VID
translate_cos (int, optional): 翻译优先级
translate_tpid (int, optional): 翻译TPID
enable_qinq (bool, optional): 使能QinQ状态
qinq_profile (str, optional): QinQ模板
service_vlan_name (str, optional): 业务VLAN名称
svlan_vid (int, optional): 业务VLAN ID
svlan_cos (int, optional): 业务VLAN 优先级
svlan_tpid (int, optional): 业务VLAN TPID。默认,33024
Returns:
int : 所配置业务的索引号
"""
cli = OLTCLI.get(olt_dev)

service_count = cli.get_onu_port_vlan_service_count(onu_dev.sn, onu_eth)
cli.set_onu_port_vlan_service_count(onu_dev.sn, onu_eth, service_count + 1)
service_index = service_count + 1


# 配置TLS
if 'tls' in kargs.keys():
validate_type('tls', kargs['tls'], bool)
cli.set_onu_port_vlan_tls(onu_dev.sn, onu_eth, service_index, kargs['tls'])

# 配置 业务区分
if 'classification' in kargs.keys():
validate_type('classification', kargs['classification'], list)
cli.set_onu_port_vlan_service_classification(onu_dev.sn, onu_eth, service_index, kargs['classification'])

# 配置 业务类型(有就配置,没有就不配置,不配置默认一般是unicast)
if 'service_type' in kargs.keys():
validate_type('service_type', kargs['service_type'], str)
cli.set_onu_port_vlan_service_type(onu_dev.sn, onu_eth, service_index, kargs['service_type'])

# 配置 CVLAN模式 部分
cvlan_mode = kargs.get('cvlan_mode', 'transparent')
cvlan_vid = kargs.get('cvlan_vid', 'null')
cvlan_cos = kargs.get('cvlan_cos', 'null')
cvlan_tpid = kargs.get('cvlan_tpid', 33024)
cli.set_onu_port_vlan_service_vlan(onu_dev.sn, onu_eth, service_index, (cvlan_mode, cvlan_cos, cvlan_tpid, cvlan_vid))

# TODO: ISP VLAN 和 COS

# TODO: 上下行带宽模板

# TODO: 数据业务带宽类型、优先级队列、GEM PORT

# 翻译设置
enable_translate = 'enable' if kargs.get('enable_translate', False) else 'disable'
translate_vid = kargs.get('translate_vid', 'null')
translate_cos = kargs.get('translate_cos', 'null')
translate_tpid = kargs.get('translate_tpid', 33024)
cli.set_onu_port_vlan_service_vlan(onu_dev.sn, onu_eth, service_index, ('translate', enable_translate, translate_cos, translate_tpid, translate_vid))

# QinQ状态
if 'enable_qinq' in kargs.keys():

assert 'qinq_profile' in kargs.keys(), '使能QinQ时, qinq_profile不能为空'
assert 'service_vlan_name' in kargs.keys(), '使能QinQ时, service_vlan_name不能为空'
assert 'svlan_vid' in kargs.keys(), '使能QinQ时, svlan vid不能为空'
assert 'svlan_cos' in kargs.keys(), '使能QinQ时, svlan cos不能为空'
assert 'svlan_tpid' in kargs.keys(), '使能QinQ时,svlan tpid不能为空'

enable_qinq = 'enable' if kargs['enable_qinq'] else 'disable'
svlan_cos = kargs['svlan_cos']
svlan_tpid = kargs['svlan_tpid']
svlan_vid = kargs['svlan_vid']
qinq_profile = kargs['qinq_profile']
service_vlan_name = kargs['service_vlan_name']

cli.set_onu_port_vlan_service_vlan(onu_dev.sn, onu_eth, service_index, ('qinq', enable_qinq, svlan_cos, svlan_tpid, svlan_vid, qinq_profile, service_vlan_name))

return service_index


# TODO: WAN 配置



__all__ = [

'clear_port_service',
'add_port_service',

]
27 changes: 27 additions & 0 deletions oltcli/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'''
olt commandline interface
'''


from typing import Union
from oltcli.utils import dotdict
from .common import *
from .an6k_17 import *

class OLTCLI:

@staticmethod
def get(olt_dev:dotdict) -> Union[OLTCLI_AN6K_17]:
"""get a olt commandline object according to given olt dev
Args:
olt_dev (Device): OLT设备资源
Returns:
OLTCLI: 返回OLTCLI类
"""

if olt_dev.model == 'AN6000-17':
return OLTCLI_AN6K_17(olt_dev)

raise RuntimeError('不支持的OLT设备型号')
Loading

0 comments on commit 640a0a7

Please sign in to comment.