TechNazgul

Sunday, January 22, 2012

After a successful 2-day quest to wrap my mind around the complexities of this DD-WRT configuration, I wanted to document my experience to hopefully save someone time in a similar situation in the future.

Background and Goal:

I'm about to move into a small office where two companies will be sharing a network environment. Our goal was to set up one router that controlled internet in/out of the office and also create two distinct, firewalled LANs, one for each company's employees. We also wanted each of the LANs to have a corresponding secured wireless network (WLAN) plus a guest network that was completely isolated from the other two.

The hardware:

I happend to have an unused Linksys (Cisco) WRT310N v1 router in my house and decided to put it to use for this job. I've installed DD-WRT on several different routers in the past, but hadn't had the occasion to configure VLANs, so this was new (and quite difficult at first) to understand.

DD-WRT Router Architecture- This article is key in understanding which ports are which on your router, which you'll have to know before you begin configuration.

Note that if you have a Gigabit router, focus on the port/vlan names in bold throughout this article. On my WRT310N, the key names/devices to know were:

Port 0: Physical WAN port

Ports 1-4: These map directly to the physical port numbers on the WRT310N. In other cases, Port 1 internally might map to the physical Port 4 on the router. You'll need to do a bit of experimenting to determine which is the case with your router. A good way to determine this is to follow the steps in "Disable LAN ports" on the Switched Ports tutorial. Disable port 1 or port 4 as explained there and take note of whether it maps to the corresponding physical port # or if it is reversed.

vlan1: vlan associated with the physical network ports 1-4

vlan2: vlan associated with the WAN socket

Port 8: Internal port connecting to the internal router (this can be confusing) - what it is important to know is that this port is required to be included in any VLAN that you wish to allow to be routed outside of that specific VLAN. (in almost every scenario you'll be including Port 8 so that the port can be routed

Subnets used in the examples below:

My main subnet (vlan2) is 192.168.20.1

My secondary subnet (vlan11) is 192.168.21.1

DD-WRT Switched Ports- this shows you how you can find the initial configuration of your router as it pertains to the VLANs.

Below is the output from my router using the commands explained on this page:

#ASSIGNS NEW VLAN11 WITH PORTS 3 & 4 FROM THE ROUTERroot@DD-WRT:~# nvram set vlan11ports="3 4 8"

#SETS HWNAME OF VLAN11root@DD-WRT:~# nvram set vlan11hwname=et0

#DEFINES CHECK BOXES FOR GUI FOR PORT 11root@DD-WRT:~# nvram set port4vlans="11 18 19"#DEFINES CHECK BOXES FOR GUI FOR PORT 11root@DD-WRT:~# nvram set port3vlans="11 18 19"#ASSIGNS VLAN 11 TO THE CPU PORT OF THE ROUTER (NORMALLY 8 IN GB ROUTER, EXCEPT IN THIS AREA OF THE CONFIG)

The directions immediately below roughly follow this tutorial (VLAN_Detached_Networks), but those steps did not work for me exactly as written, so my version is below. The linked article is very helpful, so definitely read it as well to help guide you through the process.

At this point, we've defined the two separate VLANs tied to the physical ports. Next, we have to assign the IP range for the new subnet, and follow steps to create a DHCP IP address pool for each subnet so that any computers connected to the ports receive an IP address in the correct subnet.

This can be done from Setup -> Networking.

Configure the newly created vlan11 to be unbridged. Provide a new IP address for the vlan11 subnet with a 255.255.255.0 subnet mask. This configuration does not appear to work entirely by itself in my router, so I had to enter it into the DDWRT startup script as well.

"Save" and "Apply" your settings, and at this point you can test by plugging your computer into ports 1 / 2 / 3 / 4 and confirm that you have been assigned an IP address from the right pool.

Lastly, you must isolate the networks you have created from each other. You do so by entering the following firewall rules in Administration -> Commands -> Firewall. Credit for most of these rules goes to ChristopherKois as those in the DD-WRT wiki did not work for me (thank you!)

Once in place, you can test your configuration to see if you can ping computers plugged into vlan11 when on vlan2 and vice-versa. (You should not be able to)

The last steps I followed after this were to create virtual wireless interfaces that correspond to each of the VLANs so that both companies in the office have a functional wireless network that bridges to their wired VLAN. This was relatively simple compared to the previous process. I might cover this in a future post, but if you've made it this far, you can likely follow this guide (Multiple WLANs) on your own to complete the process.

Friday, January 20, 2012

It's been a long time since my last entry, and given that the Greenpois0n Jailbreak process takes 20-30 minutes, it seemed like a great time for a quick post.

Check out LifeHacker's video guide on how to Jailbreak your A5-based iOS device. Mine is just about to complete now, after which I'm looking forward to restoring the JB apps I've been living without for the last 3 months.

Friday, March 25, 2011

Assuming you’ve tackled the annoying problem of properly auto-starting and resuming irexec (explained in part 1 and part 2), the next thing you might want to do is to be able to switch between XBMC and MythTV on the same machine. I do this mainly so that I can watch LiveTV on MythTV, and use XBMC for everything else.

As it turns out, much of the hard work has been done for us and is available on Google Code, though I’ve modified the code very slightly below to work better in my setup.

So, let’s begin:

1. Create your appswitch.pl script

I put mine in ~/home/scripts/appswitch.pl.

Be sure to replace any curly quotes ‘’ with straight quotes '' when creating your script. Also check all variables and paths in the “Global vars, paths…” section to ensure they work in your setup.

What this script does:

This script checks for what processes are running. If neither xbmc or mythtv is running, it starts xbmc. If one or the other is running, it kills the running process and starts the opposite (i.e. kills xbmc and starts myth, or vice-versa).

## Modified slightly in March of 2011 by TechNazgul ############################################################## # Require and Use Clauses. ##############################################################

2. Configure irexec to call the script via remote button press

In your home directory, you should already have a .lircrc file. You need to add to that the following code, either directly in that file, or by placing it in your ~/.lirc directory and calling it via ‘include’ in your .lircrc file. In my case, I’m doing it via an inclusion.

I used the remote button LiveTV as it wasn’t used for anything else by either XBMC or MythTV by default.

3. Restart lirc to load the new configuration

sudo /etc/init.d/lirc restart

4. Ensure irexec is running and test

Check for irexec by typing “ps –ef|grep irexec” If it isn’t, fire it up manually with:

irexec –d

Then, press the LiveTV button on your remote and wait… If it doesn’t work as planned, kill all running irexec processes and restart irexec without the –d flag. This will keep it running in the foreground and allow you to watch the script output as it progresses through it. If you see nothing, something is wrong with your irexec script. If you see script output in your terminal window, then the irexec is being successfully called via remote. You can also experiment with different options of calling irexec as root or as your user, which sometimes yields differing results with the app restart script.

Monday, February 14, 2011

It’s fairly common that for one reason or another, xbmc users need to move their video library from one location to another. Perhaps you’ve been using a single 1TB drive for your library, you’ve filled it up and upgraded to a 3TB drive and need to update the path for every movie and TV show to point to the new drive.

Or, in my case, you’ve been using windows samba-based streaming and want to move to the much more efficient NFS streaming protocol (see the comparison detailed in this post).

The simple way to change file locations is just to remove your old library, move the content, and then rescan the new destination to recreate your library in the new location. Unfortunately, this has a few big disadvantages, mainly that you lose each file’s watched status, watched count, and bookmarks, which is really annoying for large libraries.

Prerequisites

To use the solution below, there are a few things that will help ensure you can follow the steps without modification:

Your movies and TV should be sorted into individual folders, with thumbnails, trailers, nfo files, etc. all in each individual movie folder. For example, the directory for the movie 300 would include the following files:

300 [top-level movie folder]

-> .actors [folder]

-> extrathumbs [folder]

-> 300.bluray.mkv

-> 300.bluray.nfo

-> 300.bluray.tbn

-> 300.bluray-fanart.jpg

-> 300.bluray-trailer.mp4

If your library is not stored in this structure, try the ‘export library’ function within XBMC (settings –> video –> export library –> separate files) to dump all of these files to the movie directories.

You’ll want to download a tool like SQLite (if you are NOT using a shared MySQL library) or Navicat Lite (if you are using MySQL to host a shared library for multiple machines). These will allow you to browse your database and update the paths where necessary. I used Navicat, so those of you not using a shared library will have to modify the instructions slightly below to do the same thing in SQLite, which I’m not familiar with.

If using MySQL, you’ll need to remember your root password to the DB so that you can connect to it and manipulate the table data.

To be safe, you should make a copy of your video DB before starting this as you are mucking around with the sql database and there is no easy way to undo mistakes you make. In Navicat, this is as easy as, right click on xbmc_video (your video database, and select “dump SQL file.”

Updating the video database with the new path

With those items laid out as pre-requisites, here is how it’s done:

Close xbmc

Move / copy your content to the new location

Open your database using one of the tools above

Open the ‘path’ table within the xbmc_video database (or MyVideos.db for non MySQL). See the screenshot below for an example using Navicat Lite. [the username/password in my smb path has been blocked out]

You now need to open the MySQL console in Navicat to enter in the find/replace command for the path. The MySQL console can be accessed using the F6 key, or under Tools\Console in the main menu.

You’ll use a command like the one below to do the find/replace. This is a good succinct explanation of the find/replace command in MySQL if you want more info.

This replaces all SMB paths with nfs mounted paths in my root filesystem. Note that if you have different variations of the old path in your library (some with password, some without, or a separate smb://user:pass@server:/TV/ (/pictures, etc.) you’ll need to issue the above command several times until all old paths are replaced with the new location. Make sure you have all items with the old path replaced and then move on below.

Now that this much is done, you have a library with an updated path pointing to your new file locations. However, a few problems remain to be resolved. First, we have to update your sources.xml file to point to the new location as well. This file is what tells XBMC where to look for future movie/TV updates.

Open your userdata folder and edit the file sources.xml. Find all instances of your old path (smb://username:password@servername/Movies/ in my example) and replace with your new path.

Now, the hardest problem to solve. How to get XBMC to rehash all of your thumbnail files so that they still work with the new file locations. The reason this does not work automatically is that XBMC creates cached thumbnails based on the full path to the movie location. For example, if the original path was smb://username:password@servername/Movies/300, XBMC creates and caches a thumbnail based on a thumbnail hash for that directory in the userdata/Thumbnails directory.

If you change that path in the library like we did above from smb:// to /mnt/movies/300, the cached thumbnail will no longer work and you get a big ugly screen capture or no thumbnail at all in place of the thumbnail you want. The only way to force XBMC to rehash the thumbnail is to remove the item from your library or to manually refresh the information for every file in your library through a series of remote/keyboard clicks, so it’s totally impractical for a large library.

There are a lotofposts on the XBMC forums that involve using scripts to rehash the directory, but I couldn’t get any of these to work. As I was about ready to give up and just delete my library and start over, I stumbled onto a much easier solution that makes XBMC do all the heavy lifting.

Fixing the xbmc thumbnail cache after moving your library

Start in Navicat, create a new database by right-clicking anywhere in the “connections” frame, call it anything you like… in this case, xbmc_video10 (yes, it took me 10 iterations to figure this out). Enter the same options as indicated below.

This is all you need to do for now with Navicat.

Edit advancedsettings.xml in your userdata folder to change the database name from the original name to the new name xbmc_video10.

Optionally: you can delete all files in the thumbnail directory before starting this rescrape if you don’t want the extra thumbnails taking up space. I didn’t do this originally as I wasn’t sure it was going to work when I started, but I’m fairly certain you could without issue.

Update your xbmc library (right-click somewhere in the library and choose update library). This will force a rescrape of all of the sources you had previously defined in the new location. While scraping the new locations, xbmc will properly create the cached thumbnail file based on the new location. If you have large library, this will take a fair amount of time.

When done, navigate through your TV & Movie libraries and make sure everything is working. Thumbnails should show up, you should be able to play all files, etc.

Close xbmc

So at this point we have all of our thumbnails working, but we’ve lost all of our watched history, watched counts, proper ordering for date added the library, etc. We have only one more step to pair the working thumbnails with complete library history.

Edit your advanced settings.xml file again. This time, revert the change you made to the videodatabase name and enter the name of the original database. Save & close.

The next time you reopen xbmc, it will access your original library with updated paths, watched file history, and it will find all of the properly cached thumbnails that were created when you had it manually rescrape the library. Victory!

Tuesday, February 8, 2011

NETGEAR XAVB5001 500 Mbps Powerline Adapter Review:

After recently dropping my satellite subscription and moving to MythTV, I needed to find a way to get HD video streams from my antenna and HD Homerun tuner to a TV in the house without wired internet. Wireless (G or N) didn’t prove to be reliable or fast enough, so the Netgear 500 mbps (theoretical) powerline adapters seemed like a good bet.

Testing was performed in a ~3-year old house and the 2 adapters were several rooms apart from one another on the same floor. With these adapters, performance can typically vary significantly based on wiring within the house, so YMMV.

As a preview of the results, while they didn’t achieve anywhere near the advertised 250 mbps (~31 MB/s) in each direction, they did perform much better than older generation powerline adapters I’ve used. When I plugged in the adapters, the Netgear software reported that I was getting ~220 Mbps in each direction, which was encouraging, but ultimately not even close to accurate.

In addition to testing the adapters, I also wanted to test the efficiencies of different network protocols to see what would work best for streaming HD content to my XBMC / MythTV box. Below are the results.

Testing was done using commands like the following on a Ubuntu Linux machine that tests reads and write speeds to network-mounted disk.

Next, a separate set of tests was done using iperf between two Ubuntu Linux machines. The server resides on a large RAID array capable of reads and writes upwards of 500 MB/s, so disk speeds were not a limitation in this testing.

In theory, the iperf test should remove most inefficiencies related to network protocol and show raw throughput. As it turns out, the results are very similar to the NFS testing above, which speaks well of the NFS protocol.

SMB vs. NFS Conclusion:While this is probably no surprise to many, NFS is vastly more efficient. Using the same commands and testing read speeds with a 32k rsize, nfs outperforms smb by ~280%.

The difference was noticeable on XBMC performance as well. When my network shares were mounted using SMB, I was unable to smoothly stream high bitrate uncompressed 1080p bluray rips (i.e. Avatar). However, when using NFS, it played absolutely everything I could throw at it.

Netgear XAVB5001 Conclusion:

Bottom line, if your wiring is fairly modern and free of interference, while these adapters fall far short of their advertised 500 Mbps speeds, they should be more than capable of streaming your uncompressed HD content if you can serve your files via NFS. Even if you are stuck using SMB (Windows network file sharing), most of your content will work without issue, but high bitrate uncompressed bluray will likely not play 100% smoothly.