SNMP walk on only one level - snmp

Is there a way to walk only one level of the tree with SNMP?
Example:
I want to know how many tables my tree has but I don't want to walk each entry. It would be nice to only walk the parent level and return all OIDs for the root node of the table.

Rather than use snmpwalk (which I don't think supports the one level walk mentioned in question), it may be easier to get such info from the MIB file (instead of interrogating the agent).
It may be convenient to use tool like e.g. netsnmp snmptranslate. E.g. to see what tables live in SNMPv2-MIB::system i.e. 1.3.6.1.2.1.1, you could ...
snmptranslate -M +. -m +ALL -Tp -On SNMPv2-MIB::system
+--system(1)
|
+-- -R-- String sysDescr(1)
| Textual Convention: DisplayString
| Size: 0..255
+-- -R-- ObjID sysObjectID(2)
+-- -R-- TimeTicks sysUpTime(3)
| |
| +--sysUpTimeInstance(0)
|
+-- -RW- String sysContact(4)
| Textual Convention: DisplayString
| Size: 0..255
+-- -RW- String sysName(5)
| Textual Convention: DisplayString
| Size: 0..255
+-- -RW- String sysLocation(6)
| Textual Convention: DisplayString
| Size: 0..255
+-- -R-- INTEGER sysServices(7)
| Range: 0..127
+-- -R-- TimeTicks sysORLastChange(8)
| Textual Convention: TimeStamp
|
+--sysORTable(9)
|
+--sysOREntry(1)
| Index: sysORIndex
|
+-- ---- INTEGER sysORIndex(1)
| Range: 1..2147483647
+-- -R-- ObjID sysORID(2)
+-- -R-- String sysORDescr(3)
| Textual Convention: DisplayString
| Size: 0..255
+-- -R-- TimeTicks sysORUpTime(4)
Textual Convention: TimeStamp

Related

How linker place symbols in a memory section

I'm trying to figuring out how memory layout is generated by linker. I have basic knowledge about memory sections and their attributes. My question is how linker place symbols inside a specific section?
For example; a C-like array elements are guaranteed to place consecutively in the data section.
+---------+
| A[0] | 0x0000 <- An arbitrary memory address
+---------+
| A[1] | 0x0004
+---------+
| A[2] | 0x0008
+---------+
| |
| ... |
| |
+---------+
Apart from the local variables that placed in stack, how other variables are placed by the linker?
Let's assume I have two separate module foo and bar, and all of their variables will be placed to the memory without discarding by optimizations.
Module foo:
var a;
var b;
Module bar:
var a;
var b;
Is there any rule or convention for this case such as; same module variables are placed consecutively or symbol names generated by the compiler are placed alphabetically?
+-----------+
| a(foo) | \
+-----------+ -> Same module variables placed consecutively
| b(foo) | /
+-----------+
| a(bar) | \
+-----------+ -> Same module variables placed consecutively
| b(bar) | /
+-----------+
| |
| ... |
| |
+-----------+
+-----------+
| a(foo) | \
+-----------+ -> Variables placed alphabetically
| a(bar) | /
+-----------+
| b(foo) | \
+-----------+ -> Variables placed alphabetically
| b(bar) | /
+-----------+
| |
| ... |
| |
+-----------+
I've checked both GCC and LLVM documentations but couldn't find any information about this topic. Is there any place where I can look for more detailed information about address assignments or memory layout optimizations?

ArrayFormula - If cell contains match, combine other cells with TEXTJOIN

I have a Google Sheet that contains names of characters, together with corresponding values for the group name, "selected" and attack power. It looks like this:
Sheet1
| NAME | GROUP NAME | SELECTED | ATTACK POWER |
|:---------|:-----------|----------:|-------------:|
| guile | Team Red | 1 | 333 |
|----------|------------|-----------|--------------|
| blanka | Team Red | 1 | 50 |
|----------|------------|-----------|--------------|
| sagat | Team Red | | 500 |
|----------|------------|-----------|--------------|
| ruy | Team Blue | 1 | 450 |
|----------|------------|-----------|--------------|
| vega | Team Blue | 2 | 150 |
Sheet2
In my second sheet, I have two columns. Group name, which contains names of each team from Sheet1 and names, which contains my current ArrayFormula:
=ARRAYFORMULA(TEXTJOIN(CHAR(10); 1;
REPT('Sheet1'!A:A; 1*('Sheet1'!B:B=A2))))
Using this formula I can combine all characters into one cell (with textjoin, repeated with row breaks) based on the value in Group name. The result looks like the following:
| GROUP NAME | NAME |
|:-----------|:--------------------------|
| Team Red | guile |
| | blanka |
| | sagat |
|------------|---------------------------|
| Team Blue | ruy |
| | vega |
|------------|---------------------------|
The problem is that I only want to combine the characters with having a selected value of 1. End-result should instead look like this:
| GROUP NAME | NAME |
|:-----------|:--------------------------|
| Team Red | guile |
| | blanka |
|------------|---------------------------|
| Team Blue | ruy |
|------------|---------------------------|
I tried the following setup using a IF-statement, but it just returns a string of FALSE:
=ARRAYFORMULA(TEXTJOIN(CHAR(10); 1;
REPT(IF('Sheet1'!C:C="1";'Sheet1'!A:A); 1*('Sheet1'!B:B=A2))))
Can this be one?
paste in F2 cell:
=UNIQUE(FILTER(B:B, C:C=1))
paste in G2 cell and drag down:
=TEXTJOIN(CHAR(10), 1, FILTER(A:A, B:B=F2, C:C=1))
or G2 cell be like:
=ARRAYFORMULA(TEXTJOIN(CHAR(10), 1,
REPT(FILTER(Sheet1!A:A, Sheet1!C:C=1), 1*(FILTER(Sheet1!B:B, Sheet1!C:C=1)=F2))))

How many leafref is possible inside a leaf in Yang modelling?

According to RFC - RFC 6020 - LeafRef I can understand that the leaf can contain a leafref which inturn have the path pointing to the instance which is referenced but question is how many leafrefs are possible for one leaf? Only one or many?
Ex.
leaf mgmt-interface {
type leafref {
path "../interface/name";
}
type leafref {
path "../interface/ip";
}
}
Is the above possible?
A leafref may only target a single leaf or leaf-list node via path. There may only be one type substatement to a leaf (also applies to leaf-list, typedef) and there may only be a single path substatement to type.
7.6.2. The leaf's Substatements
+--------------+---------+-------------+
| substatement | section | cardinality |
+--------------+---------+-------------+
| config | 7.19.1 | 0..1 |
| default | 7.6.4 | 0..1 |
| description | 7.19.3 | 0..1 |
| if-feature | 7.18.2 | 0..n |
| mandatory | 7.6.5 | 0..1 |
| must | 7.5.3 | 0..n |
| reference | 7.19.4 | 0..1 |
| status | 7.19.2 | 0..1 |
| type | 7.6.3 | 1 | <--
| units | 7.3.3 | 0..1 |
| when | 7.19.5 | 0..1 |
+--------------+---------+-------------+
12. YANG ABNF Grammar
type-stmt = type-keyword sep identifier-ref-arg-str optsep
(";" /
"{" stmtsep
type-body-stmts
"}")
type-body-stmts = numerical-restrictions /
decimal64-specification /
string-restrictions /
enum-specification /
leafref-specification /
identityref-specification /
instance-identifier-specification /
bits-specification /
union-specification
leafref-specification =
;; these stmts can appear in any order
path-stmt stmtsep
[require-instance-stmt stmtsep]
path-stmt = path-keyword sep path-arg-str stmtend
Note: it is not possible to use union for leafref types in YANG 1.0. This has changed in YANG 1.1 however, where any built-in YANG type may appear inside a union.
9.12. The union Built-In Type
A member type can be of any built-in or derived type, except it MUST
NOT be one of the built-in types "empty" or "leafref".

Merge two trees on equal nodes

Nodes are equal when their IDs are equal. IDs in one tree are unique. On the schemas, IDs of nodes are visible.
Consider tree1:
root
|
+-- CC
| |
| \-- ZZZ
| |
| \-- UU
|
\-- A
|
\-- HAH
And tree2:
root
|
+-- A
|
+-- ADD
|
\-- HAH
I would like that merge(tree1, tree2) will give this:
root
|
+-- CC
| |
| \-- ZZZ
| |
| \-- UU
|
\-- A
|
+-- HAH
|
\-- ADD
How to do it?
Node has typical methods like getParent(), getChildren().
Order of the children doesn't matter. So, the result could be also:
root
|
+-- A
| |
| +-- ADD
| |
| \-- HAH
|
\-- CC
|
\-- ZZZ
|
\-- UU
My proposition in pseudocode. Comments are more than welcome.
merge(tree1, tree2) {
for (node : tree2.bfs()) { // for every node in breadth-first traversal order
found = tree1.find(node.getParent()); // find parent in tree1
if (found == null) // no parent?
continue; // skip it, it's root
if (!found.getChildren().contains(node)) // no node from tree2 in tree1?
found.add(node); // add it
}
return tree1;
}
The basic algorithm is not hard:
def merge_trees (t1, t2):
make_tree(map(merge_trees,assign(getChildren(t1),getChildren(t2),tree_similarity)))
make_tree(children): create a tree with the given list of children
map(f,list): calls function f on each element of list and return the list of return values
assign(list1,list2,cost_function): implements the Hungarian algorithm, returning the list of matched pairs
The trick is in defining tree_similarity which would have to call assign recursively.
In fact, the efficient implementation would have to cache the return values of the assign calls.

Listing the contents of .tgz within a .tgz

I have 300 directories with the following structure
Directory
|-- zipfile.tgz
| |-- anotherzip.tgz
| | |-- afurtherzip.tgz
| | | |-- ethernet1.txt
| | | |-- ethernet2.txt
| | | |-- ethernet3.txt
| | |-- files.txt
| |-- files.txt
|-- zipfile2.tgz
| |-- anotherzip.tgz
| | |-- afurtherzip.tgz
| | | |-- ethernet1.txt
| | | |-- ethernet2.txt
| | | |-- ethernet3.txt
| | |-- files.txt
| |-- files.txt
I need to grep the contents of the ethernetx.txt files and for any files containing 'abc=n' have it tell me the file path of the containing zipfile.tgz so i know where to find it.
Can anyone suggest a decent script / one liner i can use to achieve this? I dont want to have to recursively extrace every .tgz if i can avoid it but please let me know what you think.

Resources