RawSocket SPI java

Linux raw socket via Java DatagramChannel

Лицензия

Лицензия

Категории

Категории

Java Языки программирования AWS Контейнер PaaS Providers
Группа

Группа

com.github.alei121
Идентификатор

Идентификатор

rawsocketspi-java
Последняя версия

Последняя версия

1.0.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

RawSocket SPI java
Linux raw socket via Java DatagramChannel
Ссылка на сайт

Ссылка на сайт

http://github.com/alei121
Система контроля версий

Система контроля версий

https://github.com/alei121/rawsocketspi.git

Скачать rawsocketspi-java

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/com.github.alei121/rawsocketspi-java/ -->
<dependency>
    <groupId>com.github.alei121</groupId>
    <artifactId>rawsocketspi-java</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.alei121/rawsocketspi-java/
implementation 'com.github.alei121:rawsocketspi-java:1.0.0'
// https://jarcasting.com/artifacts/com.github.alei121/rawsocketspi-java/
implementation ("com.github.alei121:rawsocketspi-java:1.0.0")
'com.github.alei121:rawsocketspi-java:jar:1.0.0'
<dependency org="com.github.alei121" name="rawsocketspi-java" rev="1.0.0">
  <artifact name="rawsocketspi-java" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.alei121', module='rawsocketspi-java', version='1.0.0')
)
libraryDependencies += "com.github.alei121" % "rawsocketspi-java" % "1.0.0"
[com.github.alei121/rawsocketspi-java "1.0.0"]

Зависимости

Библиотека не имеет зависимостей. Это самодостаточное приложение, которое не зависит ни от каких других библиотек.

Модули Проекта

Данный проект не имеет модулей.

rawsocketspi

Java SPI for raw socket

Support for Linux raw socket only, the library uses Java SPI to provide easy access to network packet data via Java DatagramChannel.

Usage

  import java.nio.channels.DatagramChannel;
  import com.github.alei121.rawsocketspi.RSSelectorProvider;
  import com.github.alei121.rawsocketspi.RSSocketAddress;

  // Create DatagramChannel and bind it
	RSSelectorProvider provider = new RSSelectorProvider();
	DatagramChannel channel = provider.openDatagramChannel();
	RSSocketAddress address = new RSSocketAddress("eth1");
	channel.bind(address);

Maven

<dependency>
	<groupId>com.github.alei121</groupId>
	<artifactId>rawsocketspi</artifactId>
	<classifier>amd64-Linux</classifier>
	<version>1.0.0</version>
</dependency>

Blocking read/write only, no selector

rawsocketspi only implements blocking read/write.

With better CPUs, OSs, VMs..., computer systems are now more capable of handling large number of threads. For raw socket, even using one thread per port, the number of threads is still small because the number of network ports are limited by hardware and physical space. The intention of socket selector was to reduce the number of threads, in which it seems unnecessary in this case.

It is the author believes that application implementation should take the simplest form. If implementation warrents for a large number of threads, it should be handled by the lower layer (e.g. OS, VM, CPU...etc) instead of adjusting design to reduce threads.

Test setup

Testing was done in VMWare Fusion:

  • 2 custom networks vmnet2 and vmnet3 (no dhcp, no nat, no host connect)
  • 1 VM running Ubuntu 1G RAM 20G disk for build and run (add vmnet2 and vmnet3)
  • 2 VMs running Ubuntu 512G RAM for testing (one on vmnet2, one on vmnet3)

For reference my environment is:

  • VMWare Fusion 7.1.0
  • Ubuntu 14.04 and 12.04
  • OpenJDK 7

To run examples on Ubuntu with openjdk:

mvn clean install

export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/

/usr/lib/jvm/java-7-openjdk-amd64/bin/java -cp rawsocketspi-dist/target/rawsocketspi-1.0-SNAPSHOT-amd64-Linux.jar:rawsocketspi-examples/target/rawsocketspi-examples-1.0-SNAPSHOT.jar com.github.alei121.rawsocketspi.examples.SimpleCapture eth1

/usr/lib/jvm/java-7-openjdk-amd64/bin/java -cp rawsocketspi-dist/target/rawsocketspi-1.0-SNAPSHOT-amd64-Linux.jar:rawsocketspi-examples/target/rawsocketspi-examples-1.0-SNAPSHOT.jar com.github.alei121.rawsocketspi.examples.SimpleBridge eth1 eth2

More details to come...

Версии библиотеки

Версия
1.0.0