网络基础

什么是IP地址?

IP地址是一串唯一的数字字符串,由英文句点分隔标识网络上的每个设备。每个IP地址分为4个部分(八位字节),范围从0-255。

The octet breakdown of an IP address and how it totals 4 bytes.

如上所示,这意味着每个IP地址都是32位地址,这意味着有2:sup:`32`个地址,或者可能有近4300000000个地址。然而,其中大多数都公开用于web服务器之类的东西。

这带来了我们IP寻址的“第一个关键点”:网络上的每个设备都必须具有唯一的IP地址。两个设备不能具有相同的IP地址,否则会发生冲突。

Since there are only 4 billion addresses, and there are more than 4 billion computers connected to the internet, we need to be as efficient as possible with giving out IP addresses. This brings us to public vs. private addresses.

公有IP地址与私有IP地址

为了有效使用IP地址,实施了“保留IP范围”的想法。简而言之,这意味着有些IP地址范围永远不会分配给Web服务器,而只会用于本地网络,例如您家中的那些。

Key point #2: Unless you are directly connecting to your internet provider’s basic modem (no router function), your device will have an IP Address in one of these ranges. This means that at any local network, such as: your school, work office, home, etc., your device will 99% of the time have an IP address in a range listed below:

位元

起始地址

结束地址

地址数

A

24

10.0.0.0

10.255.255.255

16,777,216

B

20

172.16.0.0

172.31.255.255

1,048,576

C

16

192.168.0.0

192.168.255.255

65,536

这些保留范围使我们可以为整个房屋分配一个“未保留的IP地址”,然后使用保留范围内的多个地址将多台计算机连接到Internet。家庭互联网路由器上的一个称为NAT(网络地址转换)的过程负责处理以下过程:跟踪哪个私有IP正在请求数据,使用公共IP从Internet请求该数据,然后传递返回的数据。数据返回到请求它的专用IP。这使我们可以为许多本地网络使用相同的保留IP地址,而不会引起任何冲突。下面显示了此过程的图像。

Devices on the private network send their traffic through the NAT device to communicate to the outside network and vice versa.

备注

对于FRC | reg |网络,我们将使用“ 10.0.0.0”范围。此范围允许我们对IP地址使用“ 10.TE.AM.xx”格式,而使用B级或C级网络将仅允许一部分团队遵循该格式。对于FRC Team 1750,这种格式的示例为``10.17.50.1’’。

这些地址如何分配?

We’ve covered the basics of what IP addresses are, and which IP addresses we will use for the FRC competition, so now we need to discuss how these addresses will get assigned to the devices on our network. We already stated above that we can’t have two devices on the same network with the same IP Address, so we need a way to be sure that every device receives an address without overlapping. This can be done Dynamically (automatic), or Statically (manual).

动态地

动态分配IP地址意味着我们让网络上的设备管理IP地址分配。这是通过动态主机配置协议(DHCP)完成的。 DHCP具有许多组件,但是在本文档的范围内,我们会将其视为自动管理网络的服务。每当您将新设备插入网络时,DHCP服务都会看到该新设备,然后为其提供可用的IP地址以及该设备进行通信所需的其他网络设置。这可能意味着有时我们不知道每个设备的确切IP地址。

啥是DHCP服务器?

A DHCP server is a device that runs the DHCP service to monitor the network for new devices to configure. In larger businesses, this could be a dedicated computer running the DHCP service and that computer would be the DHCP server. For home networks, FRC networks, and other smaller networks, the DHCP service is usually running on the router; in this case, the router is the DHCP server.

这意味着,如果遇到需要DHCP服务器为网络设备分配IP地址的情况,这就像找到最近的家用路由器并将其插入一样简单。

静态

静态分配IP地址意味着我们正在手动告诉网络上的每个设备我们希望它拥有哪个IP地址。通过每个设备上的设置进行此配置。通过禁用网络上的DHCP并手动分配地址,我们的好处是可以知道网络上每个设备的确切IP地址,但是由于我们手动设置了每个设备,并且没有服务跟踪使用的IP地址,因此必须自己对此进行跟踪。在静态设置IP地址时,我们必须注意不要分配重复的地址,并且必须确保我们在每个设备上正确设置了其他网络设置(例如子网掩码和默认网关)。

FRC的IP寻址

查阅:doc:`IP Networking Article <ip-configurations>`获取更多资讯。

混合动态配置和静态配置

在场上,只要设备没有静态设置在“ 10.TE.AM.xx”范围内,并且只要没有IP地址冲突,该字段就分配DHCP地址,团队就不会在以上部分中发现任何问题。

在Pits区中,出于以下原因,团队可能会遇到混合使用静态和DHCP设备的问题。如上所述,如果没有服务器,DHCP设备将回退到本地链接地址(``169.254.xx.yy’’)。对于静态设备,IP地址将始终相同。如果不存在DHCP服务器,并且roboRIO,驱动程序站和便携式计算机回退到链接本地地址,则位于10.TE.AM.xx范围内的静态设置的设备将位于不同的网络中,并且对于使用链接本地地址。下面提供了对此的直观描述:

How you can't mix link-local and static IP configurations.

警告

通过USB连接到roboRIO时,需要配置:ref:docs/networking/networking-utilities/portforwarding:Port Forwarding 来连接OpenMesh路由器设备(在上面显示的绿色网络上)。

Available Network Ports

Please see R704 of the 2024 Game Manual for information regarding available network ports.

mDNS

mDNS或多播域名系统是一种协议,它使我们可以从DNS的功能中受益,而无需在网络上安装DNS服务器。为了更清楚地说明这一点,让我们退后一步,谈谈什么是DNS。

什么是DNS?

DNS (Domain Name System) can become a complex topic, but for the scope of this paper, we are going to just look at the high-level overview of DNS. In the most basic explanation, DNS is what allows us to relate human-friendly names for network devices to IP Addresses, and keep track of those IP addresses if they change.

Example 1: Let’s look at the site www.google.com. The IP address for this site is 172.217.164.132, however that is not very user-friendly to remember!

Whenever a user types www.google.com into their computer, the computer contacts the DNS server (a setting provided by DHCP!) and asks what is the IP address on file for www.google.com. The DNS server returns the IP address and then the computer is able to use that to connect to the Google website.

示例2:在您的家庭网络上,您有一个要从笔记本电脑连接到的名为``MYCOMPUTER’’的服务器。您的网络使用DHCP,因此您不知道“ MYCOMPUTER”的IP地址,但是DNS允许您仅使用“ MYCOMPUTER”名称进行连接。此外,每当DHCP分配刷新时,“ MYCOMPUTER”可能会以不同的地址结尾,但是由于您是通过使用“ MYCOMPUTER”名称而不是特定的IP地址进行连接的,因此DNS记录已更新,您仍然能够连接。

This is the second benefit to DNS and the most relevant for FRC. With DNS, if we reference devices by their friendly name instead of IP Address, we don’t have to change anything in our program if the IP Address changes. DNS will keep track of the changes and return the new address if it ever changes.

FRC的DNS

On the field and in the pits, there is no DNS server that allows us to perform the lookups like we do for the Google website, but we’d still like to have the benefits of not remembering every IP Address, and not having to guess at every device’s address if DHCP assigns a different address than we expect. This is where mDNS comes into the picture.

mDNS为我们提供了与传统DNS相同的优势,但是仅以不需要服务器的方式实现。每当用户要求使用友好名称连接到设备时,mDNS都会发出一条消息,要求具有该名称的设备标识自己。然后,具有该名称的设备将发送包括其IP地址的返回消息,以便网络上的所有设备都可以更新其信息。 mDNS使我们可以将roboRIO称为``roboRIO-TEAM-FRC.local’’并将其连接到DHCP网络上。

备注

如果用于FRC的设备不支持mDNS,则会为该设备分配10.TE.AM.20-10.TE.AM.255范围内的IP地址,但我们不知道要连接的确切地址,我们将无法像以前一样使用友好名称。在这种情况下,设备将需要具有静态IP地址。

mDNS-原理

Multicast Domain Name System (mDNS) is a system which allows for resolution of hostnames to IP addresses on small networks with no dedicated name server. To resolve a hostname a device sends out a multicast message to the network querying for the device. The device then responds with a multicast message containing its IP. Devices on the network can store this information in a cache so subsequent requests for this address can be resolved from the cache without repeating the network query.

mDNS-提供者

要使用mDNS,必须在您的PC上安装mDNS工具。以下是每个主要平台的一些常见mDNS工具:

Windows:

  • NI mDNS Responder: 用NI FRC Game Tools安装。

  • Apple Bonjour: iTunes内安装

OSX:

  • Apple Bonjour: 默认安装

Linux:

  • nss-mDNS/Avahi/Zeroconf: 默认在某些Linux变体(例如Ubuntu或Mint)上安装并启用。可能需要在其他产品(例如Arch)上安装或启用

mDNS - 防火墙

备注

根据您的PC配置,可能不需要进行任何更改,此部分用于帮助进行故障排除。

为了正常工作,必须允许mDNS穿过防火墙。因为网络流量来自mDNS实施,而不是直接来自Driver Station或IDE,所以仅允许那些应用程序通过是不够的。解决mDNS防火墙问题的主要方法有两种:

  • 为mDNS实施添加应用程序/服务例外(NI mDNS Responder为 C:\Program Files\National Instruments\Shared\mDNS Responder\nimdnsResponder.exe

  • 为往返于UDP 5353的流量添加端口例外。IP范围:

    • 10.0.0.0 - 10.255.255.255

    • 172.16.0.0 - 172.31.255.255

    • 192.168.0.0 - 192.168.255.255

    • 169.254.0.0 - 169.254.255.255

    • 224.0.0.251

mDNS-浏览器支持

只要安装了mDNS提供程序,大多数Web浏览器就应该能够使用mDNS地址访问roboRIO Web服务器。这些浏览器包括Microsoft Edge,Firefox和Google Chrome。

USB

如果使用USB接口,则无需进行网络设置(您将需要ref:`docs/zero-to-robot/step-2/frc-game-tools:Installing the FRC Game Tools`以提供roboRIO USB驱动)。 roboRIO驱动程序将自动配置主机(您的计算机)的IP地址,并且roboRIO和上面列出的软件应该能够找到并利用您的roboRIO。

以太网/无线

The 给你的路由器编程 will enable the DHCP server on the OpenMesh radio in the home use case (AP mode), if you are putting the OpenMesh in bridge mode and using a router, you can enable DHCP addressing on the router. The bridge is set to the same team-based IP address as before (10.TE.AM.1) and will hand out DHCP address from 10.TE.AM.20 to 10.TE.AM.199. When connected to the field, FMS will also hand out addresses in the same IP range.

总结

IP地址使我们能够与网络上的设备进行通信。对于FRC,如果我们连接到DHCP服务器或静态分配了这些地址,则这些地址将在10.TE.AM.xx范围内,或者在本地链接的``169.254.xx.yy’’范围内如果设备设置为DHCP,但是不存在服务器。有关IP地址如何工作的更多信息,请参见微软的这篇文章 this

如果网络上的所有设备均支持mDNS,则可以将所有设备设置为DHCP并使用其友好名称进行引用(例如``roboRIO-TEAM-FRC.local’’)。如果某些设备不支持mDNS,则需要将其设置为使用静态地址。

如果将所有设备都设置为使用DHCP或静态IP分配(具有正确的静态设置),则通讯应在Pits区和场地内均可进行,而无需进行任何更改。如果混合使用某些静态设备和某些DHCP设备,则静态设备将在场地内进行连接,但不会在Pits区中进行连接。可以通过以下方式解决此问题:将所有设备设置为静态设置,或者保留当前设置并在Pits区中提供DHCP服务器。