经过一系列的研究学习,知识储备之后,终于,可以开始研究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路线图的更多相关文章

  1. 【hyperscan】编译hyperscan 4.0.0

    ref: http://01org.github.io/hyperscan/dev-reference/getting_started.html 1. 硬件需求 intel x86处理器 64-bit ...

  2. [hyperscan] hyperscan 1到1.5 --!!

    [hyperscan][pkg-config] hyperscan 从0到1路线图 接续前文,继续深入理解: 概述: 1.  自动机理论,是hyperscan的理论基础. https://zh.wik ...

  3. Hyperscan与Snort的集成方案

    概况 Hyperscan作为一款高性能的正则表达式匹配库,非常适用于部署在诸如DPI/IPS/IDS/NGFW等网络解决方案中.Snort (https://www.snort.org) 是目前应用最 ...

  4. 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 ...

  5. 如何在windows下成功的编译和安装python组件hyperscan

    摘要:hyperscan 是英特尔推出的一款高性能正则表达式引擎,一次接口调用可以实现多条规则与多个对象之间的匹配,可以支持多种匹配模式,块模式和流模式,它是以PCRE为原型开发,并以BSD许可证开源 ...

  6. OpenShift Container Platform 4.3.0部署实录

    本文参照红帽官方文档,在裸机安装Openshift4.3文档进行.因为只有一台64G内存的PC机,安装vmware vsphere 6.7免费版进行本测试,所以尝试在OCP官方文档要求的最低内存需求基 ...

  7. yoyogo v1.7.4 发布,支持 grpc v1.3.8 & etcd 3.5.0

    YoyoGo (Go语言框架)一个简单.轻量.快速.基于依赖注入的微服务框架( web .grpc ),支持Nacos/Consoul/Etcd/Eureka/k8s /Apollo等 . https ...

  8. 跨平台日志清理工具 Log-Cutter v2.0.1 正式发布

    Log-Cutter 是JessMA开源组织开发的一个简单实用的日志切割清理工具.对于服务器的日常维护来说,日志清理是非常重要的事情,如果残留日志过多则严重浪费磁盘空间同时影响服务的性能.如果用手工方 ...

  9. ExtJS 中类的选项 - config

    首先看一个例子,我们在ExtJS中定义一个Window对象,代码如下: var win = Ext.create("Ext.window.Window", { title: '示例 ...

随机推荐

  1. pandas DataFrame.shift()函数

    pandas DataFrame.shift()函数可以把数据移动指定的位数 period参数指定移动的步幅,可以为正为负.axis指定移动的轴,1为行,0为列. eg: 有这样一个DataFrame ...

  2. js实现禁止pc端浏览器缩放和获取当前页面浏览器的缩放大小

    众所周知:移动端页面禁止用户缩放界面只需加上<meta name="viewport" content="user-scalable=0">即可,但 ...

  3. 使用C#+Linq+SQL快速开发业务

    C#开发桌面程序的效率确实很高,今天就来总结下如何使用C#+Linq+SQL快速开发一个新的业务系统. Linq是微软官方的轻量级的ORM工具,使用它结合SQL可以快速的生成实体类,再通过Linq操作 ...

  4. linux基础知识 【转】

    linux目录架构 / 根目录 /bin 常用的命令 binary file 的目錄 /boot 存放系统启动时必须读取的档案,包括核心 (kernel) 在内 /boot/grub/menu.lst ...

  5. redis Sentinel部署

    sentinel 系统用于管理多个 Redis 服务器(instance) 执行以下三个任务: 监控(Monitoring): Sentinel 会不断地检查你的主服务器和从服务器是否运作正常. 提醒 ...

  6. Python内置类型——dict

    Python中, 字典是容器,所以可以使用len()方法统计字典中的键值对的个数: 字典是可迭代的,迭代的依据是字典中的键. in, not in 等运算符判断指定的键是否在字典中: 如果索引一个字典 ...

  7. R语言三元相图的做法

    通常情况下,对于三维数据,我们会用三维图表来展示,想要从三维图表上观察出一定的规律,需要一定的空间想象力: 而三元相图,其实就是用二维平面的1个等边三角形来表征三维数据,三角形的每一条边对应1个维度, ...

  8. Windows 8(64位)如何搭建 Android 开发环境与真机测试(转)

    可以参考http://wenku.baidu.com/link?url=ghU6IFS1WJXLFKfM_0efv9YQEnMDBrdi9CXwirSs5IOLLeUfdIOh8OOVv0DX89Lt ...

  9. Python 中的map、reduce函数用法

    #-*- coding:UTF-8 -*- #map()函数接受两个参数,一个是函数,一个是序列,map将传入的函数依次作用到序列的每个元素,并把结果作为新的list返回 def f(x): retu ...

  10. [JS] Topic - why "strict mode" here

    Ref: Javascript 严格模式详解 使得Javascript在更严格的条件下运行: - 消除Javascript语法的一些不合理.不严谨之处,减少一些怪异行为; - 消除代码运行的一些不安全 ...