如何用语言对 OSI 参考模型进行编程
我正在研究网络和 OSI 模型以及所有 7 层。 就像每一层如何放置自己的标头然后在接收端删除一样。
有什么方法可以让我用 java 或 c 或 c++ 创建程序,然后手动执行分层完成的每个步骤,以便我真正知道它的实际工作原理
编辑: 好的,首先考虑本地 例如,我有数据词“hello”,我想将其发送到另一个正在运行的模拟 OSI 模型的程序。这个词将穿过所有层,它们将像 OSI 一样添加标头和内容,然后其他正在运行的程序将收到它。
我认为基本上 TCP/ip 协议必须进行编程,但可能有经验的人可以做得更好
,然后我可以手动更改位以检查错误控制是否正常工作
I am studying networking and OSI model and all 7 layers.
Like how each layer puts its own header and then removes on the receiver end.
Is there any way that i can create the program in java or c or c++ and i manually perform each step which is done at layers so that i actually know how it actually works
Edit:
ok first consider locally
For example i have data word "hello" and i want to send it to another running program simulating the OSI model. That word ill go trough the all layers and they will add their headers and stuff like OSI does and then other running program will receive it.
Basically TCP/ip protocol has to be programmed i think but may be experineced person can get it better
then i can manually change the bits to check whether error control works ok or not
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于 OSI 模型有 7 层:
并且您想要在 Java(或可能是 C)环境中模拟它,那么您将需要做适量的工作。
出于模拟的目的,您可能会将普通的 TCP/IP 套接字层视为物理层 - 在模拟中,它实现端点之间的连接。它是一个非常可靠的物理层,但你不可能拥有一切。
然后,您可以使用适当的代码来模拟每个连续层 - 链路、网络、传输、会话、表示、应用程序层,将数据放入数据包中,或拆分数据包,并添加标头和校验和等。除应用程序外的每一层都有两个接口:向下接口(到较低编号的层)和向上接口(到较高编号的层)。您需要为每一层决定适当的操作。最小的集合可能是:打开、关闭、读取、写入。
我会从简单的开始 - 从底部或顶部(任一方向都可以)。由于无论如何您都需要一个应用程序(如果没有别的,请测试代码),因此您可以从那里开始。您将不断完善代码并添加额外的层,以确保以前的功能继续发挥作用。您必须弄清楚应用程序层如何将其所需的信息传递给数据链路层 - 以便可以进行正确的套接字调用等。
祝您玩得开心。
Since the OSI model has 7 layers:
and you want to emulate it in a Java (or possibly C) environment, then you're going to need to do a moderate amount of work.
For the purposes of your simulation, you'd probably treat the normal TCP/IP sockets layer as the physical layer - in your simulation, it achieves connectivity between endpoints. It is a remarkably reliable physical layer, but you can't have everything.
You can then simulate each of the successive layers - Link, Network, Transport, Session, Presentation, Application - layers with appropriate code that puts data into packets, or splits up packets, and adds headers and check sums and so on. Each layer except the application has two interfaces: the downward interface (to the lower-numbered layer) and the upward interface (to the higher-numbered layer). You'll need to decide on appropriate operations for each layer. A minimal set is likely to be: open, close, read, write.
I'd start simple - with either the bottom or the top (either direction could work). Since you'll need an application anyway (test code if nothing else), you might start there. You'll successively refine the code adding extra layers, ensuring the previous functionality continues to work. You'll have to work out how the application layer conveys to the data link layer the information that it needs - so that the correct socket calls can be made, etc.
Have fun.