VLAN Technology: XEN creates an Intranet
Steps:
1. Create a Network
2. Create a VLAN
Several internal operations are involved when creating a VLAN.
● Create a Vlan object (① in the figure)
● Create a PIF (② in the figure) to connect the created VLAN (① in the figure) to the created Network (step 1)
● Vlan (① in the figure) and PIF (③ in the figure) are connected
Note:
1. A tag is a unique identifier of a VLAN (under the same PIF) in the range of 0-4096. That is to say, only 4096 + 1 VLAN can be created under a PIF.
2. A Network can only be associated with a PIF, just as a VDI can only be associated with a VBD, therefore, when a Network is associated with a PIF, it cannot be associated with another PIF (where X is shown in the figure)
Code:
- Network. Record networkRecord = new Network. Record ();
- NetworkRecord. nameLabel = "for_vlan_test_1 ";
- NetworkRecord. nameDescription = "for_vlan_test_1 ";
- NetworkRecord. MTU = 1500L; // maximum transmission unit, take the configuration file constant, 1500L
- NetworkRecord. otherConfig = null;
- Network network = Network. create (connection, networkRecord );
-
- Long tag = 801L;
- PIF taggedPIF = PIF. getByUuid (connection, "8a6dfb4d-187f-a5d0-7e35-bd8d81a301a7"); // PIF indicates ③
- // Create vlan
- VLAN vlan = VLAN. create (connection, taggedPIF, tag, network );