经过一系列的研究学习,知识储备之后,终于,可以开始研究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. (转) mysql中left join,right join,inner join的区别

    转自:https://blog.csdn.net/qq_35975416/article/details/78842958 sql查询中有一个非常重要的环节就是表的关联查询,一般使用left join ...

  2. 使用Qt Creator进行linux远程调试

    序言 考虑到程序员在无桌面Linux的环境下编写C/C++程序,如果使用原生的Vim编辑和单步断点调试比较麻烦,不利于新手使用,所以笔者尝试使用Qt实现两台Linux电脑远程部署和调试.即程序员在调试 ...

  3. oracle 11g 使用物化视图远程增量刷新数据

    ① 源数据库建立物化视图日志 drop MATERIALIZED VIEW LOG ON ORG_BASEINFO/ CREATE MATERIALIZED VIEW LOG ON ORG_BASEI ...

  4. @Autowired注入为null问题分析

    题说明 最近看到Spring事务,在学习过程中遇到一个很苦恼问题 搭建好Spring的启动环境后出现了一点小问题 在启动时候却出现[java.lang.NullPointerException] 不过 ...

  5. ABBYY FineReader 12使用教程

    说到OCR图文识别软件,自然少不了ABBYY FineReader 12.ABBYY FineReader 12可快速方便地将扫描纸质文档.PDF文件和数码相机的图像转换成可编辑.可搜索的文本.我们已 ...

  6. easyui tree 默认选中第一个元素

    系统采用ajax异步调用后端接口做数据呈现,有个场景就是加载的树形菜单默认选中第一行,网上有人分享的解决方案能实现效果(http://aokunsang.iteye.com/blog/1489204) ...

  7. rem布局在react中的应用

    摘要: 前面给大家分享了一个react项目(http://www.cnblogs.com/xiyangbaixue/p/4751904.html),这次对这个项目做了一些改进,增加了rem布局和对is ...

  8. 使用 wondershaper 在 Linux 中限制网络带宽使用

    wondershaper 实际上是一个 shell 脚本,它使用 tc 来定义流量调整命令,使用 QoS 来处理特定的网络接口.外发流量通过放在不同优先级的队列中,达到限制传出流量速率的目的:而传入流 ...

  9. 理解AppDomain

    在传统的 Win32的程序中,进程是独立的运行空间, 在一些大型系统中, 通常都是将系统中的核心功能分解出来用独立的进程来处理,一方面是为了能获得更高的系统性能.吞吐量 .另一方面是为了能隔离功能之间 ...

  10. 面试题思考:GET和POST两种基本请求方法的区别

    面试回答: GET请求在URL中传送的参数是有长度限制的,而POST没有. GET比POST更不安全,因为参数直接暴露在URL上,所以不能用来传递敏感信息. GET参数通过URL传递,POST放在Re ...