翻遍整个网络都没有找到用ipv6进行组播推流的实例。
朋友说:A true strong person never complains about the environment
那么,就由我来创造一个吧~
此文涉及到的所有软件均为开源软件,进行深入学习与其他平台移植时十分便利。
记得点赞额~
gns3介绍与安装
gns3,The software that empowers network professionals
支持私有vm、qemu、virtalbox、docker镜像、kvm等各种镜像,丰富的网络与GUI可视化界面
应用场景广泛,如:sonic
安装方式:https://docs.gns3.com/docs/
kvm方式安装gns3
解压kvm包,然后执行如下命令启动。
sudo virt-install \--name GNS3VM \--memory 20048 \--vcpus 8 \--disk path=/your/files/path/gns3/'GNS3 VM-disk001.qcow2',format=qcow2,bus=virtio \--disk path=/your/files/path/gns3/'GNS3 VM-disk002.qcow2',format=qcow2,bus=virtio \--network network=default,model=virtio \--import \--os-type=linux \--os-variant=generic
NOTE:路径根据实际目录替换
拓扑环境规划
- 主机1、组播源(docker容器)
- eth0(ens3),fc00:0:0:2006::6/64
- 主机2、组播接收者(qemu-ubuntu18.04)
- eth0(ens3),fc00:0:0:2008::8/64
- frr路由器,3台,版本10.0.1
- R1
- eth0,fc00:0:0:2001::2/64
- eth1,fc00:0:0:2008::1/64
- R2
- eth1,fc00:0:0:2001::1/64
- eth2,fc00:0:0:2003::1/64
- R3
- eth0,fc00:0:0:2003::3/64
- eth1,fc00:0:0:2006::1/64
模拟器:gns3
收发组播包工具:python3(也可用vlc、iperf2等)
可选项
- 交换机:ovs(https://github.com/openvswitch/ovs)
- 控制器:onos(https://github.com/opennetworkinglab/onos)
环境配置
涉及知识点
- ipv6组播,PIMv6
https://docs.frrouting.org/en/latest/pimv6.html
pim6d supports pim-sm as well as MLD v1 and v2. PIMv6 is vrf aware and can work within the context of vrf’s in order to do S,G mrouting.
具体为PIM SM中的ASM
2. ipv6-OSPF,OSPFv3
https://docs.frrouting.org/en/latest/ospf6d.html
ospf6d is a daemon support OSPF version 3 for IPv6 network. OSPF for IPv6 is described in RFC 2740.
路由器配置
R1、R2、R3都打开OSPFv6与PIM6
sed -i ‘s/ospf6d=no/ospf6d=yes/g’ /etc/frr/daemons
sed -i ‘s/pim6d=no/pim6d=yes/g’ /etc/frr/daemons
R1
#/etc/frr/mgmtd.conf
!
hostname frr10-1
!
interface eth0ipv6 address fc00:0:0:2001::2/64
exit
interface eth1ipv6 address fc00:0:0:2008::1/64
exit
!
#/etc/frr/ospf6d.conf
!
interface eth0ipv6 ospf6 area 0.0.0.0ipv6 ospf6 instance-id 0
!
router ospf6ospf6 router-id 1.1.1.1area 0.0.0.0 range fc00:0:0:2001::/64redistribute connected
!
R2
#/etc/frr/mgmtd.conf
hostname frr10-2
!
interface eth1ipv6 address fc00:0:0:2001::1/64
exit
!
interface eth2ipv6 address fc00:0:0:2003::1/64
exit
!
#/etc/frr/ospf6d.conf
!
interface eth1ipv6 ospf6 area 0.0.0.0ipv6 ospf6 instance-id 0
!
interface eth2ipv6 ospf6 area 0.0.0.0ipv6 ospf6 instance-id 0
!
router ospf6ospf6 router-id 2.2.2.2area 0.0.0.0 range fc00:0:0:2001::/64area 0.0.0.0 range fc00:0:0:2003::/64redistribute connected
!
R3
#/etc/frr/mgmtd.conf
hostname frr10-3
!
interface eth0ipv6 address fc00:0:0:2003::3/64
exit
!
!
interface eth1ipv6 address fc00:0:0:2006::1/64
exit
!
#/etc/frr/ospf6d.conf
!
interface eth0ipv6 ospf6 area 0.0.0.0ipv6 ospf6 instance-id 0
!
router ospf6ospf6 router-id 3.3.3.3area 0.0.0.0 range fc00:0:0:2003::/64redistribute connected
!
中间路由节点(R1、R2、R3)打开ip转发
# /etc/frr/zebra.conf
ipv6 forwarding
为简化部署,笔者写了一个一键部署脚本,地址为:
https://github.com/puhaiyang/frr_gns_demo/blob/main/gns3_multicast/multicast_ipv6.py
主机配置
组播源主机–网络配置
ifconfig eth0 inet6 add fc00:0:0:2006::6/64
route -A inet6 add default gw fc00:0:0:2006::1 eth0
查看方式route -6 -n
验证:
root@multicast-sender:~# ping6 fc00:0:0:2006::1
PING fc00:0:0:2006::1(fc00:0:0:2006::1) 56 data bytes
64 bytes from fc00:0:0:2006::1: icmp_seq=1 ttl=64 time=0.838 ms
64 bytes from fc00:0:0:2006::1: icmp_seq=2 ttl=64 time=0.728 ms
组播接收者–网络配置
vim /etc/netplan/01-network-manager-all.yaml
---
network:version: 2ethernets:ens3:addresses:- fc00:0:0:2008::8/64gateway6: fc00:0:0:2008::1
#生效ip配置
sudo netplan apply
验证
主机通信验证
所有主机与路由器使用ipv6均互相可达
组播通信验证
接收者脚本
recv_multicast.py
import socket
import struct# bind udp socket
sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)# bind a multicast address
multicast_group_ip = 'ffe8::2'
port = 5007
sock.bind(('::', port))# 告诉内核加入多播组
group = socket.inet_pton(socket.AF_INET6, multicast_group_ip)
# 第二个参数是接口索引,此处修改为实际接口填写
mreq = group + struct.pack('@I', 2)
sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_JOIN_GROUP, mreq)print(f"绑定到组播地址 {multicast_group_ip}:{port}")# 接收数据
while True:data, addr = sock.recvfrom(1024)print(f"Received message: {data} from {addr}")
IPv6组播地址参考
发送者脚本
send_multicast.py
import socket
import datetime# Multicast group and port
multicast_group_ip = 'ffe8::2'
port = 5007# Create a UDP socket
sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM, socket.IPPROTO_UDP)# Set the time-to-live for messages to 5 hops
ttl = 5
sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_MULTICAST_HOPS, ttl)# Get the current time
current_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')# Create the message with current time and IP address using .format()
message = 'Hello, Multicast Group! Time: {}'.format(current_time).encode('utf-8')# Send the multicast message
sock.sendto(message, (multicast_group_ip, port))
print("Sent message:", message.decode('utf-8'))
验证结果
接收端执行
python3 recv_multicast.py
发送端执行
python3 send_multicast.py
vlc方式推流
vlc --intf ncurses --vout dummy --aout dummy hdvideo.mp4 --sout udp:[ffe8::2] --ttl 6 --repeat
vlc推流示例截图
中间链路抓包
发包前组播路由截图
发包后组播路由截图
frr调试方式
验证过程中如发现网络不通,可打开frrouting的debug并配置日志进行查看
示例为:
touch /var/log/ttt.log
chmod 777 /var/log/ttt.logvtysh
enable
configure terminal
log file /var/log/ttt.log
debug pim
debug mlb
ovs与onos验证
给ONOS配置cloud网络后访问对应的http后台:
http://[yourBrigeIp]:8181/onos/ui
启动openflow
org.onosproject.openflow
然后再ovs中配置控制器,指定到onos的ip
#ovs
ip addr add 192.168.1.11/24 dev eth15
#onos
ip addr add 192.168.1.222/24 dev eth0
#onos与ovs网络可达
ping 192.168.1.11
#ovs-add ctl
ovs-vsctl set bridge br0 protocols=OpenFlow13
ovs-vsctl set-controller eth0 tcp:192.168.1.222:6653
控制器上查看流表
查看流表ovs-ofctl dump-flows br0
OpenvSwitch-1:/$ ovs-ofctl dump-flows br0cookie=0x0, duration=2965.183s, table=0, n_packets=319, n_bytes=35017, priority=0 actions=NORMAL
本文涉及到的配置与脚本已上传至github:https://github.com/puhaiyang/frr_gns_demo