[hyperscan][pkg-config] hyperscan 从0到1路线图
经过一系列的研究学习,知识储备之后,终于,可以开始研究hyperscan了。
[knowledge][模式匹配] 字符匹配/模式匹配 正则表达式 自动机
[knowledge][perl][pcre][sed] sed / PCRE 语法/正则表达式
[development][PCRE] PCRE
----------------------------------------------------------------------
Now, let‘s hyperscan! 2333333
中文介绍:https://www.sdnlab.com/18773.html
官网: https://01.org/zh/hyperscan
正式入口:https://github.com/intel/hyperscan
开发者手册:http://intel.github.io/hyperscan/dev-reference/preface.html
官方例子程序:在源码的 examples/ 子目录。
其中用到了一个比较特殊的依赖库: Ragel http://www.colm.net/open-source/ragel/
Understanding the formal relationship between regular expressions and deterministic finite automata is key to using Ragel effectively.
理解正则表达式与确定有限状态自动机之间的关系,是用好这个库的关键。
提一个题外的编译系统 Ninja https://ninja-build.org/
编译一下:
┬─[tong@T7:~/Src/thirdparty/github]─[:: PM]
╰─>$ git clone git@github.com:intel/hyperscan.git
┬─[tong@T7:~/Src/thirdparty/github]─[:: PM]
╰─>$ cd hyperscan/
┬─[tong@T7:~/Src/thirdparty/github/hyperscan]─[:: PM]
╰─>$ mkdir BUILD
[root@dpdk hyperscan]# cd BUILD/
编译之前,需要安装boost,或者下载boost的源码。 仅在编译的时候需要boost的头文件而已,并不需要编译boost,也不需要安装boost的运行时库。
┬─[tong@T7:~/Src/thirdparty]─[:: PM]
╰─>$ wget https://dl.bintray.com/boostorg/release/1.66.0/source/boost_1_66_0.tar.bz2
┬─[tong@T7:~/Src/thirdparty]─[:: PM]
╰─>$ tar jxf boost_1_66_0.tar.bz2
还需有安装 Ragel-devel
[root@dpdk BUILD]# yum install ragel-devel
开始编译:
[root@dpdk BUILD]# cmake -DBOOST_ROOT=~/src/thirdparty/boost_1_66_0/ ../
[root@dpdk BUILD]# cmake --build .
[root@dpdk BUILD]# make
测试编译是否成功:
[root@dpdk BUILD]# ./bin/unit-hyperscan
读开发手册:http://intel.github.io/hyperscan/dev-reference/
备注:
模糊匹配之
莱文斯坦距离:https://zh.wikipedia.org/wiki/萊文斯坦距離
汉明距离:https://zh.wikipedia.org/wiki/%E6%B1%89%E6%98%8E%E8%B7%9D%E7%A6%BB
API:http://intel.github.io/hyperscan/dev-reference/api_files.html
指定安装路径:
[root@dpdk BUILD]# cmake -DCMAKE_INSTALL_PREFIX=~/src/thirdparty/github/hyperscan/BUILD/DIST/ ../
[root@dpdk BUILD]# make
[root@dpdk BUILD]# make install
安装后的内容:
[root@dpdk DIST]# tree
.
├── include
│ └── hs
│ ├── hs_common.h
│ ├── hs_compile.h
│ ├── hs.h
│ └── hs_runtime.h
├── lib64
│ ├── libhs.a
│ ├── libhs_runtime.a
│ └── pkgconfig
│ └── libhs.pc
└── share
└── doc
└── hyperscan
└── examples
├── patbench.cc
├── pcapscan.cc
├── README.md
└── simplegrep.c directories, files
例子: share/doc/hyperscan/examples/simplegrep.c
编译:
gcc -o simplegrep simplegrep.c $(pkg-config --cflags --libs libhs)
引申内容:pkt-config
介绍:https://zh.wikipedia.org/wiki/Pkg-config
主页:https://www.freedesktop.org/wiki/Software/pkg-config/
On most systems, pkg-config looks in /usr/lib/pkgconfig, /usr/share/pkgconfig, /usr/local/lib/pkg‐
config and /usr/local/share/pkgconfig for these files. It will additionally look in the colon-separated (on Windows,
semicolon-separated) list of directories specified by the PKG_CONFIG_PATH environment variable.
默认情况下,pkg-config会到以下四个目录中查找,/usr/lib/pkgconfig, /usr/share/pkgconfig, /usr/local/lib/pkg‐config and /usr/local/share/pkgconfig
之后,还会查找环境变量PKG_CONFIG_PATH 中的路径。
因为,我的hyperscan 没有安装在标准路径下,所以:
[tong@T7 pkgconfig]$ export PKG_CONFIG_PATH=~/Src/thirdparty/github/hyperscan/BUILD/DIST/lib64/pkgconfig
[tong@T7 pkgconfig]$ pkg-config --cflags --libs libhs
-I/root/src/thirdparty/github/hyperscan/BUILD/DIST/include/hs -L/root/src/thirdparty/github/hyperscan/BUILD/DIST/lib -lhs
[tong@T7 pkgconfig]$
增加一个软链接:
[root@dpdk DIST]# ln -rfs lib64/ lib
[root@dpdk DIST]# ll
total
drwxr-xr-x root root Jan : include
lrwxrwxrwx root root Jan : lib -> lib64
drwxr-xr-x root root Jan : lib64
drwxr-xr-x root root Jan : share
[root@dpdk DIST]#
编译:
[root@dpdk examples]# cat build.sh
#! /usr/bin/bash export PKG_CONFIG_PATH=/root/src/thirdparty/github/hyperscan/BUILD/DIST/lib64/pkgconfig
g++ -o simplegrep simplegrep.c $(pkg-config --cflags --libs libhs)
测试运行:
[root@dpdk examples]# ./simplegrep init simplegrep.c
Scanning bytes with Hyperscan
[root@dpdk examples]#
块内容模式匹配的例子:
https://github.com/tony-caotong/knickknack/tree/master/examples/hyperscan
效果如下:
[root@dpdk hyperscan]# ./test
Usage: ./test <pattern> <string>
[root@dpdk hyperscan]# ./test dafkj1234dlkfajf
id: , matched position:
[root@dpdk hyperscan]# ./test dafkj1234dl1234kfajf
id: , matched position:
id: , matched position:
[root@dpdk hyperscan]#
查看例子源码,修改编译,可以做多模式匹配:
默认的两个pattern为 1234, 5678
效果如下:
[root@dpdk hyperscan]# ./test ""
id: , matched position:
id: , matched position:
[root@dpdk hyperscan]# ./test "dfasfdsaf1234gadgdgdahg5678"
id: , matched position:
id: , matched position:
[root@dpdk hyperscan]# ./test "dfasfdsaf1234gadgdgdahg5678dfsag"
id: , matched position:
id: , matched position:
[root@dpdk hyperscan]#
修改例子中的宏,可以开启流匹配模式
默认的两个pattern为1234,5678. 运行时的俩个参数可以组合成一个流。
效果如下:
[root@dpdk hyperscan]# ./test "dfasfdsaf1234gad" "gdgdahg5678dfsag"
id: , matched position:
id: , matched position:
[root@dpdk hyperscan]# ./test "dfasfdsaf123" "4gadgdgdahg5678dfsag"
id: , matched position:
id: , matched position:
[root@dpdk hyperscan]#
continue:
[hyperscan] hyperscan 1到1.5 --!!
[hyperscan][pkg-config] hyperscan 从0到1路线图的更多相关文章
- 【hyperscan】编译hyperscan 4.0.0
ref: http://01org.github.io/hyperscan/dev-reference/getting_started.html 1. 硬件需求 intel x86处理器 64-bit ...
- [hyperscan] hyperscan 1到1.5 --!!
[hyperscan][pkg-config] hyperscan 从0到1路线图 接续前文,继续深入理解: 概述: 1. 自动机理论,是hyperscan的理论基础. https://zh.wik ...
- Hyperscan与Snort的集成方案
概况 Hyperscan作为一款高性能的正则表达式匹配库,非常适用于部署在诸如DPI/IPS/IDS/NGFW等网络解决方案中.Snort (https://www.snort.org) 是目前应用最 ...
- anaconda2下面安装opencv2.4.13.4完成----解决默认安装的问题----Thefunction is not implemented. Rebuild the library with Windows, GTK+ 2.x orCarbon support. If you are on Ubuntu or Debian, install libgtk2.0‑dev and pkg
转载自:http://blog.csdn.net/qingyanyichen/article/details/73550924 本人下载编译安装了opencv2.4.9,oppencv2.4.10,o ...
- 如何在windows下成功的编译和安装python组件hyperscan
摘要:hyperscan 是英特尔推出的一款高性能正则表达式引擎,一次接口调用可以实现多条规则与多个对象之间的匹配,可以支持多种匹配模式,块模式和流模式,它是以PCRE为原型开发,并以BSD许可证开源 ...
- OpenShift Container Platform 4.3.0部署实录
本文参照红帽官方文档,在裸机安装Openshift4.3文档进行.因为只有一台64G内存的PC机,安装vmware vsphere 6.7免费版进行本测试,所以尝试在OCP官方文档要求的最低内存需求基 ...
- yoyogo v1.7.4 发布,支持 grpc v1.3.8 & etcd 3.5.0
YoyoGo (Go语言框架)一个简单.轻量.快速.基于依赖注入的微服务框架( web .grpc ),支持Nacos/Consoul/Etcd/Eureka/k8s /Apollo等 . https ...
- 跨平台日志清理工具 Log-Cutter v2.0.1 正式发布
Log-Cutter 是JessMA开源组织开发的一个简单实用的日志切割清理工具.对于服务器的日常维护来说,日志清理是非常重要的事情,如果残留日志过多则严重浪费磁盘空间同时影响服务的性能.如果用手工方 ...
- ExtJS 中类的选项 - config
首先看一个例子,我们在ExtJS中定义一个Window对象,代码如下: var win = Ext.create("Ext.window.Window", { title: '示例 ...
随机推荐
- 对于移动端 App,虚拟机注册或类似作弊行为有何应对良策?
1.APP攻击大致策略 对APP进行攻击的一般思路包括反编译APP代码.破解APP通讯协议.安装虚拟机自动化模拟: a.首先看能否反编译APP代码(例如Android APP),如果能够反编译,从代码 ...
- 详解CUDA编程
CUDA 是 NVIDIA 的 GPGPU 模型,它使用 C 语言为基础,可以直接以大多数人熟悉的 C 语言,写出在显示芯片上执行的程序,而不需要去学习特定的显示芯片的指令或是特殊的结构.” 编者注: ...
- tensorflow 笔记11:tf.nn.dropout() 的使用
tf.nn.dropout:函数官网说明: tf.nn.dropout( x, keep_prob, noise_shape=None, seed=None, name=None ) Defined ...
- linux每日命令(27):chmod命令
chmod命令用于改变linux系统文件或目录的访问权限.用它控制文件或目录的访问权限.该命令有两种用法.一种是包含字母和操作符表达式的文字设定法:另一种是包含数字的数字设定法. Linux系统中的每 ...
- 利用堆实现堆排序&优先队列
数据结构之(二叉)堆一文在末尾提到"利用堆能够实现:堆排序.优先队列.".本文代码实现之. 1.堆排序 如果要实现非递减排序.则须要用要大顶堆. 此处设计到三个大顶堆的操作:(1) ...
- 【30集iCore3_ADP出厂源代码(ARM部分)讲解视频】30-4 底层驱动之ADC、DAC
源视频包下载地址:链接:http://pan.baidu.com/s/1cL37gM 密码:ys1l 银杏科技优酷视频发布区:http://i.youku.com/gingko8
- vue.js在visual studio 2017下的安装
1.打开"工具"菜单->"NuGet 包管理器"->"管理解决方案 Nuget 的程序包": 在红色标识的地方输入vue: 2. ...
- .NET Memory Allocation Profiling with Visual Studio 2012
.NET Memory Allocation Profiling with Visual Studio 2012 This post was written by Stephen Toub, a fr ...
- 驱动文件中只有cat/inf/dll文件,怎么安装
网上下载了一个驱动,里面包含文件只有cat/inf/dll文件,怎么安装? 1.计算机-右键-管理-设备管理器,找到要装驱动的设备上 2.右键-更新驱动程序-浏览到本地的这个驱动文件夹 3.开始安装
- 关于tomcat的session问题
因为有需要每一个项目有独立端口,并且能够单独启动和关闭,所以在一台服务器上配置了多个tomcat.tomcat是完全一样的,只是各自的端口不一致. 现在的问题是单独启动一个tomcat完全没有问题. ...